home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / live / usr / lib / LST / libLSTall < prev    next >
Encoding:
Text File  |  2002-10-23  |  298.6 KB  |  12,978 lines

  1. # libLSTall global functions shared between several scripts
  2. #
  3. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  4. # Copyright (C) 1998-2001 Ralf Flaxa, Caldera (Deutschland) GmbH,
  5. #                         Erlangen, Germany
  6. #
  7. # $Id: libLSTall,v 3.225 2001/04/10 14:28:53 rf Exp $
  8. #
  9.  
  10. #
  11. # global settings (should be moved to lst.cnf)
  12. #
  13.  
  14. # first it is in MB (for convenience)
  15. SPARESPACE=5
  16. # from now on its in Bytes (for granularity)
  17. SPARESPACE="`do_calc $SPARESPACE \* 1048576`"
  18. NUM_DOINST=0
  19. ROOT_INITIALIZED=0
  20. touch $FILE_VALUES_SEL
  21.  
  22. INSTALL_MODE=OpenLinux
  23.  
  24. Is_SPARC()
  25. {
  26.     if [ "`uname -m`" = "sparc" ]; then
  27.         return 0
  28.     else
  29.         return 1
  30.     fi
  31. }
  32.  
  33. if Is_SPARC ; then
  34.     RPMBINEXT=sparc
  35. else
  36.     RPMBINEXT=i386
  37. fi
  38.  
  39. case $INSTALL_MODE in
  40. LST)
  41.   # LST settings
  42.   INSTALL_MODE=LST
  43.   CONF_INSTALL_PATH_SRC=/lst_22
  44.   PKGEXT=rpm
  45.   ;;
  46. COL)
  47.   # LST settings
  48.   INSTALL_MODE=LST
  49.   CONF_INSTALL_PATH_SRC=/col
  50.   PKGEXT=rpm
  51.   ;;
  52. OpenLinux)
  53.   # LST settings
  54.   INSTALL_MODE=OpenLinux
  55.   CONF_INSTALL_PATH_SRC=/col
  56.   PKGEXT=rpm
  57.   ;;
  58. esac
  59.  
  60. #
  61. # libLSTmini
  62. #
  63. CMD_Still_Missing()
  64. {
  65.   echo "lisa: sorry, command not yet supported..." 1>&2
  66.   false
  67. }
  68.  
  69. Do_KDE_add()
  70. {
  71.     [ ! -x "$CMD_KDEAPPS" ] || $CMD_KDEAPPS add "$@"
  72. }
  73.  
  74. Do_KDE_remove()
  75. {
  76.     local app="$1"
  77.     local trigger="$2"
  78.  
  79.     [ "$trigger" != "0" ] && return 0
  80.  
  81.     [ ! -x "$CMD_KDEAPPS" ] || $CMD_KDEAPPS remove "$app"
  82. }
  83.  
  84. Do_SysVinit()
  85. {
  86.   local script=
  87.   local callname=
  88.   local levels=
  89.  
  90.   while read script callname levels; do
  91.     for i in `echo $levels | sed -e 's/:/ /g'`; do
  92.       mkdir -p $DIR_INIT_CONF/rc$i.d >/dev/tty8 2>&1
  93.       ln -sf ../init.d/$script $DIR_INIT_CONF/rc$i.d/$callname >/dev/tty8 2>&1
  94.     done
  95.   done
  96. }
  97.  
  98. Do_SysVinit_install()
  99. {
  100.   local subsys="$1"
  101.   local start="$2$1"
  102.   local slevels="$3"
  103.   local stop="$4$1"
  104.   local klevels="$5"
  105.  
  106.   # consistency check
  107.   #FIXME!?
  108.  
  109.   # cleanup
  110.   Do_SysVinit_remove $subsys 0
  111.  
  112.   # create start- and stoplinks
  113.   local name=$start
  114.   for l in $slevels $klevels; do
  115.     for i in `echo $l | sed -e 's/:/ /g'`; do
  116.       [ -d $DIR_INIT_CONF/rc$i.d ] || mkdir -p $DIR_INIT_CONF/rc$i.d
  117.       ln -sf ../init.d/$subsys $DIR_INIT_CONF/rc$i.d/$name
  118.     done
  119.     name=$stop
  120.   done
  121. }
  122.  
  123. Do_SysVinit_remove()
  124. {
  125.   local subsys="$1"
  126.   local trigger="$2"
  127.  
  128.   [ "$trigger" != "0" ] && return 0
  129.  
  130.   # consistency check
  131.   #FIXME!?
  132.  
  133.   rm -f $DIR_INIT_CONF/rc?.d/[SK][0-9][0-9]$subsys
  134. }
  135.  
  136. Info_FindFile()
  137. {
  138.   local topic=$1
  139.   local file
  140.  
  141.   if [ -n "`echo $topic | sed -n 's:^/.*$:OK:p'`" ]; then
  142.     if [ -r $topic ]; then
  143.       file=$topic
  144.     elif [ -r $topic.info ]; then
  145.       file=$topic.info
  146.     elif [ -r $topic.gz ]; then
  147.       file=$topic.gz
  148.     elif [ -r $topic.info.gz ]; then
  149.       file=$topic.info.gz
  150.     fi
  151.   elif [ -r $DIR_INFO/$topic ]; then
  152.     file=$DIR_INFO/$topic
  153.   elif [ -r $DIR_INFO/$topic.info ]; then
  154.     file=$DIR_INFO/$topic.info
  155.   elif [ -r $DIR_INFO/$topic.gz ]; then
  156.     file=$DIR_INFO/$topic.gz
  157.   elif [ -r $DIR_INFO/$topic.info.gz ]; then
  158.     file=$DIR_INFO/$topic.info.gz
  159.   fi
  160.   echo $file
  161. }
  162.  
  163. Do_Info_install()
  164. {
  165.   Check_Info_Not_OLD || { Do_Info_install_OLD "$@"; return $?; }
  166.  
  167.   local topic="$1"; shift
  168.   local file
  169.  
  170.   # consistency check
  171.   #FIXME!?
  172.  
  173.   file=`Info_FindFile $topic`
  174.  
  175.   if [ -z "$file" ] || [ ! -r "$file" ]; then
  176.     Debug "Do_Info_install $topic not found"
  177.     return 1
  178.   fi
  179.  
  180.   $CMD_INSTALL_INFO "$@" $file $DIR_INFO/dir
  181.   return 0
  182. }
  183.  
  184. Do_Info_remove()
  185. {
  186.   Check_Info_Not_OLD || { Do_Info_remove_OLD "$@"; return $?; }
  187.  
  188.   local topic="$1"; shift
  189.   local trigger="$1"; shift
  190.   local file
  191.  
  192.   [ "$trigger" != "0" ] && return 0
  193.  
  194.   # consistency check
  195.   #FIXME!?
  196.  
  197.   file=`Info_FindFile $topic`
  198.  
  199.   if [ -z "$file" ] || [ ! -r "$file" ]; then
  200.     Debug "Do_Info_remove $topic not found"
  201.     return 1
  202.   fi
  203.  
  204.   $CMD_INSTALL_INFO --remove $file $DIR_INFO/dir
  205.   return 0
  206. }
  207.  
  208. # backward-compatibility ...
  209. Check_Info_Not_OLD()
  210. {
  211.   local v=`$CMD_INSTALL_INFO --version | sed -n '1s/^[^0-9]*//p'`
  212.   [ "$v" != "3.11" ] && return 0
  213.   return 1
  214. }
  215.  
  216. Info_GetCmd()
  217. {
  218.   local file="$1"
  219.   local cmd=cat
  220.  
  221.   [ -n "`echo $file | sed -n 's/^.*\.gz$/OK/p'`" ] &&
  222.     cmd=zcat
  223.   echo $cmd
  224. }
  225.  
  226. Do_Info_install_OLD()
  227. {
  228.   local topic="$1"; shift
  229.   local file
  230.   local cmd
  231.  
  232.   # consistency check
  233.   #FIXME!?
  234.  
  235.   file=`Info_FindFile $topic`
  236.   cmd=`Info_GetCmd $file`
  237.  
  238.   if [ -z "$file" ] || [ ! -r "$file" ]; then
  239.     Debug "Do_Info_install $1 not found"
  240.     return 1
  241.   fi
  242.  
  243.   $cmd $file | $CMD_INSTALL_INFO "$@" - $DIR_INFO/dir
  244.   return 0
  245. }
  246.  
  247. Do_Info_remove_OLD()
  248. {
  249.   local topic="$1"
  250.   local trigger="$2"
  251.   local file
  252.   local cmd
  253.  
  254.   [ "$trigger" != "0" ] && return 0
  255.  
  256.   # consistency check
  257.   #FIXME!?
  258.  
  259.   file=`Info_FindFile $topic`
  260.   cmd=`Info_GetCmd $file`
  261.  
  262.   if [ -z "$file" ] || [ ! -r "$file" ]; then
  263.     Debug "Do_Info_remove $1 not found"
  264.     return 1
  265.   fi
  266.  
  267.   $cmd $file | $CMD_INSTALL_INFO --remove - $DIR_INFO/dir
  268.   return 0
  269. }
  270.  
  271. Do_Inetd_install()
  272. {
  273.   # consistency check in inetdconf!?
  274.  
  275.   $CMD_INETDCONF --add "$@"
  276. }
  277.  
  278. Do_Inetd_remove()
  279. {
  280.   local service="$1"
  281.   local trigger="$2"
  282.  
  283.   [ "$trigger" != "0" ] && return 0
  284.  
  285.   # further consistency check in inetdconf!?
  286.  
  287.   $CMD_INETDCONF --remove "$service"
  288. }
  289.  
  290. Do_Inetd()
  291. {
  292.   local command="$1"
  293.   
  294.   shift 1
  295.   case "$command" in
  296.   "install"|"remove")
  297.     Do_Inetd_${command} "$@"
  298.     return $?
  299.     ;;
  300.   "enable"|"disable")
  301.     [ $# -gt 0 ] && { local service=$1; shift; }
  302.     [ $# -gt 0 ] && { local trigger=$1; shift; }
  303.     [ "$trigger" != "0" ] && return 0
  304.     # further consistency check in inetdconf!?
  305.     $CMD_INETDCONF --$command "$service" "$@"
  306.     return $?
  307.     ;;
  308.   *)
  309.     Print_Usage
  310.     ;;
  311.   esac
  312. }
  313.  
  314. Do_User()
  315. {
  316.   local command="$1"; shift
  317.  
  318.   case "$command" in
  319.   "create")
  320.     CMD_Still_Missing
  321.     ;;
  322.   "revoke")
  323.     CMD_Still_Missing
  324.     ;;
  325.   *)
  326.     Print_Usage
  327.     ;;
  328.   esac
  329. }
  330.  
  331. Do_Group_Join()
  332. {
  333.   local gname="$1"; shift
  334.   local i
  335.  
  336.   for i in "$@"; do
  337.     false
  338.   done
  339.   CMD_Still_Missing
  340. }
  341.  
  342. Do_Group_Leave()
  343. {
  344.   CMD_Still_Missing
  345. }
  346.  
  347. Do_Group()
  348. {
  349.   local command="$1"; shift
  350.   local gname="$1"; shift
  351.  
  352.   case "$command" in
  353.   "create")
  354.     $CMD_GROUP $command $gname "$@"
  355.     ;;
  356.   "join")
  357.     Do_Group_Join $gname "$@"
  358.     ;;
  359.   "leave")
  360.     [ "$1" != "0" ] && return 0; shift
  361.  
  362.     Do_Group_Leave $gname "$@"
  363.     ;;
  364.   "revoke")
  365.     [ "$1" != "0" ] && return 0; shift
  366.  
  367.     $CMD_GROUP $command $gname "$@"
  368.     ;;
  369.   *)
  370.     Print_Usage
  371.     ;;
  372.   esac
  373. }
  374.  
  375. #
  376. # libAnalyse
  377. #
  378.  
  379. Store_Detected_Info()
  380. {
  381.   local cd1_dev
  382.  
  383.   # we store all detected hardware infos in /etc/system.cnf as default
  384.   sysinfo --cdrom --var > /dev/null 2> /tmp/cdrom
  385.   if [ -s /tmp/cdrom ]; then
  386.     cd1_dev="`cut -d':' -f 2 /tmp/cdrom | sed -n '1p'`"
  387.     if [ -n "$cd1_dev" ]; then
  388.       case $cd1_dev in
  389.       /dev/sr0)
  390.         cd1_dev=/dev/scd0
  391.         ;;
  392.       /dev/sr1)
  393.         cd1_dev=/dev/scd1
  394.         ;;
  395.       esac
  396.       set_val CONF_CD1_DEV "$cd1_dev"
  397.     fi
  398.   fi
  399.   return 0
  400. }
  401.  
  402. #
  403. # libModule
  404. #
  405.  
  406. Show_Hardware_Found()
  407. {
  408.   local tmpfile=/tmp/LST/ans
  409.   local what="HARDWARE"
  410.  
  411.   if [ $# -gt 0 -a "$1" = "generic" ]; then
  412.     what="HARDWARE_GENERIC"
  413.   fi
  414.  
  415.   Info ":INFO_ANALYSE_RUNNING:"
  416.   sysinfo --notitle --short > $tmpfile
  417.   if [ ! -s $tmpfile ]; then
  418.     Msg2 HARDWARE_NOT_FOUND || return 1
  419.     return 0
  420.   fi
  421.   Browse2 $tmpfile ${what}_FOUND || return 1
  422.   return 0
  423. }
  424.  
  425. Warn_Autoprobe_Dangerous()
  426. {
  427.   Msg2 AUTOPROBE_DANGEROUS || return 1
  428.   return 0
  429. }
  430.  
  431. Do_Autoprobe()
  432. {
  433.   local what=
  434.   local how=
  435.  
  436.   # CD probelists (sbpcd takes too much time)
  437.   local cd_probelist_kernel="cdu31a mcd mcdx sbpcd aztcd sonycd535 gscd arcd bpcd bpmcd dscd eicd epcd kicd oicd pwcd cm206 optcd sjcd isp16"
  438.   local cd_probelist="cdu31a mcd mcdx aztcd sonycd535 gscd arcd bpcd bpmcd dscd eicd epcd kicd oicd pwcd cm206 optcd sjcd isp16"
  439.   local cd_probelist_cautious=""
  440.  
  441.   # SCSI probelists (g_NCR5380 hangs)
  442.   local scsi_probelist_kernel="advansys BusLogic u14-34f ultrastor aha152x aha1542 aha1740 aic7xxx fdomain in2000 g_NCR5380 NCR53c406a qlogicfas qlogicisp pas16 seagate t128 dtc tmscsim 53c7,8xx ncr53c8xx eata_dma eata_pio wd7000 eata AM53C974 ppa gdth"
  443.   local scsi_probelist="advansys BusLogic u14-34f ultrastor aha152x aha1542 aha1740 aic7xxx fdomain in2000 NCR53c406a qlogicfas qlogicisp pas16 seagate t128 dtc tmscsim 53c7,8xx ncr53c8xx eata_dma eata_pio wd7000 eata ppa gdth"
  444.   local scsi_probelist_cautious="aha1542 ncr53c8xx 53c7,8xx aic7xxx"
  445.  
  446.   # net probelists
  447.   local ether_probelist_cautious="3c59x ne2k-pci 3c509 ne"
  448.   local ether_probelist_kernel="de4x5 dgrs eepro100 epic100 hp100 ne2k-pci pcnet32 rtl8139 3c59x tulip yellowfin ac3200 smc-ultra32 at1700 smc-ultra smc9194 wd 3c503 hp hp-plus seeq8005 e2100 ne at1500 fmv18x eth16i 3c509 3c515 znet eexpress eepro depca ewrk3 apricot 3c501 3c507 3c505 de600 de620 ni52 ni65 lance tlan"
  449.   # the at1500 is part of the e2100 ?
  450.   # the 3c501 is always misdetected :-(
  451.   # the seeq8005 and znet are not modularized :-(
  452.   local ether_probelist="de4x5 dgrs eepro100 epic100 hp100 ne2k-pci pcnet32 rtl8139 3c59x tulip yellowfin ac3200 smc-ultra32 at1700 smc-ultra smc9194 wd 3c503 hp hp-plus e2100 ne fmv18x eth16i 3c509 3c515 eexpress eepro depca ewrk3 apricot 3c507 3c505 ni52 ni65 lance tlan atp de600 de620"
  453.  
  454.   local driver=
  455.   local modparam=
  456.   local all=1
  457.   local retval=
  458.   local success=
  459.  
  460.   what="$1"
  461.   shift 1
  462.  
  463.   case $what in
  464.   all)
  465.     # simulate full kernel autoprobing by load & test of all modules
  466.     # first we probe for CDROMs, then for SCSI hosts and last for ethernet
  467.     probelist="$cd_probelist $scsi_probelist $ether_probelist"
  468.     probelist_cautious="$cd_probelist_cautious $scsi_probelist_cautious $ether_probelist_cautious"
  469.     ;;
  470.   CD)
  471.     probelist="$cd_probelist"
  472.     probelist_cautious="$cd_probelist_cautious"
  473.     ;;
  474.   SCSI)
  475.     probelist="$scsi_probelist"
  476.     probelist_cautious="$scsi_probelist_cautious"
  477.     ;;
  478.   NET)
  479.     probelist="$ether_probelist"
  480.     probelist_cautious="$ether_probelist_cautious"
  481.     ;;
  482.   esac
  483.  
  484.   if [ $# -gt 0 -a "$1" = "cautious" ]; then
  485.     probelist="$probelist_cautious"
  486.     all=0
  487.   fi
  488.  
  489.   Info ":INFO_AUTOPROBE_RUNNING:"
  490.  
  491.   for driver in $probelist ; do
  492.     modparam=
  493.     if [ "$driver" = "ne" ]; then
  494.       # NE2000 cards need an io parameter. 0x300 is very common.
  495.       modparam="io=0x300"
  496.     fi
  497.     Debug "probing ${driver} driver:"
  498.     Do_Load_Module_mini --silent $driver $modparam
  499.     retval=$?
  500.     if [ $retval -eq 0 ]; then
  501.       success=1
  502.     fi
  503.   done
  504.   if [ -n "$success" ]; then
  505.     return 0
  506.   else
  507.     return 1
  508.   fi
  509. }
  510.  
  511. Ask_Autoprobe()
  512. {
  513.   local what="AUTOPROBE"
  514.  
  515.   if [ $# -gt 0 -a "$1" = "cautious" ]; then
  516.     what="AUTOPROBE_CAUTIOUS"
  517.   fi
  518.   Ask bool ${what} y || return 1
  519.   return 0
  520. }
  521.  
  522. Ask_Hardware_Sufficient()
  523. {
  524.   local what="HARDWARE"
  525.   local defval=y
  526.  
  527.   if [ $# -gt 0 -a "$1" = "generic" ]; then
  528.     what="HARDWARE_GENERIC"
  529.     defval=n
  530.   fi
  531.   Ask bool ${what}_SUFFICIENT $defval || return 1
  532.   return 0
  533. }
  534.  
  535. Find_Module()
  536. {
  537.   if [ -f $1.o ]; then return 0 ; fi
  538.   if [ -f $1.o.gz ]; then return 0 ; fi
  539.   if [ -f /floppy/$1.o ]; then return 0 ; fi
  540.   if [ -f /floppy/$1.o.gz ]; then return 0 ; fi
  541.   if [ -f /source/$1.o ]; then return 0 ; fi
  542.   return 1
  543. }
  544.  
  545.  
  546. Build_Modules_Available()
  547. {
  548.   local modpath=/lib/modules/`uname -r`
  549.   local mode="$1"
  550.   local goal="$2"
  551.   local driver=
  552.   local modparam=
  553.   local subdir=
  554.   local list=
  555.   local scsi_support="scsi_mod sd_mod sg sr_mod st"
  556.   local scsi_driver="aha152x aha1542 aha1740 aic7xxx advansys AM53C974 BusLogic tmscsim dtc eata eata_dma eata_pio fdomain gdth in2000 g_NCR5380 ppa in2000 NCR53c406a 53c7,8xx ncr53c8xx pas16 qlogic qlogicfas qlogicisp seagate t128 ultrastor u14-34f wd7000"
  557.   local cdrom_driver="aztcd cdrom gscd hitcd isp16 cm206 sbpcd mcd mcdx optcd sjcd cdu31a sonycd535 arcd bpcd bpmcd dscd eicd epcd kicd oicd pwcd"
  558.   local net_support="8390 bsd_comp depca dlci dummy eql new_tunnel plip ppp sdla slhc slip"
  559.   local net_driver="3c501 3c503 3c505 3c507 3c509 3c59x ac3200 apricot arcnet at1700 atp de4x5 de600 de620 depca dgrs e2100 eepro eepro100 eexpress eth16i ewrk3 fmv18x hp hp-plus hp100 ibmtr lance ne ne2k-pci ni52 ni65 pcnet32 rtl8139 smc9194 smc-ultra smc-ultra32 tlan tulip wd yellowfin"
  560.   local fs_driver="binfmt_aout binfmt_elf binfmt_java ext ext2 hpfs isofs ncpfs nfs smbfs sysv ufs vfat xiafs"
  561.  
  562.  
  563.   case $goal in
  564.   FS)
  565.     list="$fs_driver"
  566.     modpath=$modpath/fs
  567.     ;;
  568.   CD)
  569.     list="$cdrom_driver"
  570.     modpath=$modpath/cdrom
  571.     ;;
  572.   SCSI)
  573.     # list="$scsi_support $scsi_driver"
  574.     list="$scsi_driver"
  575.     modpath=$modpath/scsi
  576.     ;;
  577.   NET)
  578.     # list="$net_support $net_driver"
  579.     list="$net_driver"
  580.     modpath=$modpath/net
  581.     ;;
  582.   ANY)
  583.     echo "\"DONE\" \":MENU_BACK:\" \\"
  584.     Build_MODULES_AVAILABLE
  585.     return 0
  586.     ;;
  587.   esac
  588.  
  589.   if [ "$mode" = "box" ]; then
  590.     # echo "\"NONE\" \":TYPE_${goal}_NONE:\" \\"
  591.     echo "\"DONE\" \":TYPE_${goal}_DONE:\" \\"
  592.     echo "\"AUTO\" \":TYPE_${goal}_AUTO:\" \\"
  593.   fi
  594.   for driver in $list ; do
  595.     Find_Module $modpath/$driver
  596.     if [ $? -eq 0 ]; then
  597.       if [ "$mode" = "box" ]; then
  598.     echo "\"$driver\" \":TYPE_${goal}_$driver:\" \\"
  599.       else
  600.     echo "$driver"    
  601.       fi
  602.     fi
  603.   done
  604.   if [ "$mode" = "box" ]; then
  605.     echo "\"OTHER\" \":TYPE_${goal}_OTHER:\" \\"
  606.   fi
  607. }
  608.  
  609.  
  610. Map_LILO_2_Insmod_Param()
  611. {
  612.   local lilo_param="$1"
  613.   local var1="$2"
  614.   local var2="$3"
  615.   local var3="$4"
  616.   local var4="$5"
  617.   local val1
  618.   local val2
  619.   local val3
  620.   local val4
  621.  
  622.   if [ -z "`sed -n "/^$lilo_param=/p" $FILE_BOOT_PARAMS`" ]; then
  623.     echo ""
  624.     return 1
  625.   fi
  626.  
  627.   case $lilo_param in
  628.   aztcd|gscd|cm206|sonycd535|optcd)
  629.     # for LILO and insmod the params are the same
  630.     sed -n "/^$lilo_param=/p" $FILE_BOOT_PARAMS
  631.     return 0
  632.     ;;
  633.   mcd)
  634.     sed -n '/^mcd=/s/^mcd=\([^,]*\),\(.*\)/mcd_port=\1 mcd_irq=\2/p' $FILE_BOOT_PARAMS
  635.     return 0
  636.     # mcd_port
  637.     # mcd_irq
  638.     # mitsumi_bug_93_wait
  639.     ;;
  640.   aic7xxx)
  641.     if [ -n "`sed -n '/^aic7xxx=extended,no_reset/p' $FILE_BOOT_PARAMS`" ]; then
  642.       echo "aic7xxx_extended=1 aic7xxx_no_reset=1"
  643.       return 0
  644.     fi
  645.     ;;
  646.   cdu31a)
  647.     sed -n '/^cdu31a=/s/^cdu31a=\([^,]*\),\(.*\)/cdu31a_port=\1 cdu31a_irq=\2/p' $FILE_BOOT_PARAMS
  648.     return 0
  649.     # cdu31a_port
  650.     # cdu31a_irq
  651.     # sony_pas_init
  652.     ;;
  653.   isp16)
  654.     ;;
  655.   sbpcd)
  656.     ;;
  657.   esac
  658.   return 0
  659. }
  660.  
  661. Do_Load_Module_mini()
  662. {
  663.   local silent_flag=
  664.   local ans=/tmp/LST/ans
  665.   local err=/tmp/LST/err
  666.   local modpath=/lib/modules/`uname -r`
  667.   local subpath=
  668.   local module=
  669.   local driver=
  670.   local modparam=
  671.   local modlist=/tmp/modules.initrd
  672.  
  673.   if [ $# -gt 0 -a "$1" = '--silent' ]; then
  674.     silent_flag=true
  675.     shift 1
  676.   fi
  677.  
  678.   driver="$1"
  679.   shift 1
  680.   modparam="$@"
  681.  
  682.   if [ -z "$modparam" ]; then
  683.     # check for LILO boot params
  684.     case $driver in
  685.     mcd|gscd|aztcd|cm206|cdu31a|aic7xxx|sonycd535|optcd)
  686.       modparam="`Map_LILO_2_Insmod_Param $driver`"
  687.       ;;
  688.     esac
  689.   fi
  690.  
  691.   # check whether it's already loaded
  692.   /sbin/lsmod | sed -n "/^$driver/p" > $ans
  693.   if [ -s $ans ]; then
  694.     return 0
  695.   fi
  696.  
  697.   # check whether it's available and prepare it for loading
  698.   for subpath in block cdrom fs ipv4 misc net pcmcia scsi ; do
  699.     mkdir -p $modpath/$subpath
  700.     module="$modpath/$subpath/${driver}.o"
  701.     if [ -s $module ]; then
  702.       break
  703.     elif [ -s $module.gz ]; then
  704.       gunzip $module.gz
  705.       break
  706.     elif [ -s /source/$module ]; then
  707.       module=/source/$module
  708.       break
  709.     elif [ -s /floppy/$module ]; then
  710.       module=/floppy/$module
  711.       break
  712.     elif [ -s /floppy/$module.gz ]; then
  713.       gzip -dcf /floppy/$module.gz > $module
  714.       break
  715.     fi
  716.     module=
  717.   done 
  718.  
  719.   if [ -z "$module" ]; then
  720.     if [ -z "$silent_flag" ]; then
  721.       Msg "module ${driver}.o ; :ERR_MODULE_NOT_AVAILABLE:"
  722.     fi
  723.     return 1
  724.   fi 
  725.  
  726.   while [ 1 ]; do
  727.     if [ -z "$silent_flag" ]; then
  728.       Info "module ${driver}.o ; :INFO_MODULE_LOADING:"
  729.       sleep 2
  730.     fi
  731.     Debug "trying <insmod $module $modparam> ... "
  732.     /sbin/insmod $module $modparam >$err 2>&1 && break
  733.     /sbin/rmmod $driver >/dev/null 2>&1
  734.     Debug "insmod ${driver} failed."
  735.     if [ -z "$silent_flag" ]; then
  736.       Info "module ${driver}.o ; :ERR_MODULE_LOADING_FAILED:"
  737.       sleep 3
  738.     fi
  739.     end_use $module
  740.     return 1
  741.   done
  742.   Debug "insmod ${driver} succeeded."
  743.   # FIXME: in the success case we do not compress the module any more
  744.   # end_use $module
  745.   if [ -z "$silent_flag" ]; then
  746.     Msg "module ${driver}.o ; :INFO_MODULE_LOADED:"
  747.   fi
  748.   echo "$driver" >> $modlist
  749.   mkdir -p /etc/modules/options
  750.   if [ -n "$modparam" ]; then
  751.     echo "$modparam" > /etc/modules/options/$driver
  752.   else
  753.     rm -f /etc/modules/options/$driver
  754.   fi
  755.   return 0
  756. }
  757.  
  758. Load_Default_Modules()
  759. {
  760.   local driver=
  761.  
  762.   for driver in $@ ; do
  763.     Do_Load_Module_mini --silent $driver "" || return 1
  764.   done
  765.   return 0
  766. }
  767.  
  768.  
  769. Choose_Module()
  770. {
  771.   local modpath=/lib/modules/`uname -r`
  772.   local goal="$1"
  773.   local driver=AUTO
  774.   local insmod_params=
  775.   local default_cd=""
  776.   local default_scsi="scsi_mod sd_mod sr_mod st sg"
  777.   local default_ether="8390"
  778.   local default_modules=
  779.  
  780.   case $goal in
  781.   CD)
  782.     default_modules="$default_cd"
  783.     ;;
  784.   SCSI)
  785.     default_modules="$default_scsi"
  786.     ;;
  787.   NET)
  788.     default_modules="$default_ether"
  789.     ;;
  790.   ANY)
  791.     MountModulesFloppy
  792.     ;;
  793.   esac
  794.  
  795.   Load_Default_Modules $default_modules
  796.  
  797.   while [ 1 ]; do
  798.     Ask one MODULE_LOAD --default "$driver" Build_Modules_Available box $goal || return 1
  799.     driver="$ANSWER"
  800.     insmod_params=
  801.     # if [ "$driver" = "NONE" ]; then
  802.     if [ "$driver" = "DONE" ]; then
  803.       return 0
  804.     fi
  805.     if [ "$driver" = "OTHER" ]; then
  806.       MountModulesFloppy
  807.       continue
  808.     fi
  809.     if [ "$driver" = "ne" ]; then insmod_params="io=0x300" ; fi
  810.     if [ "$driver" = "AUTO" ]; then
  811.       Ask_Autoprobe
  812.       if [ "$ANSWER" != "0" ]; then
  813.         continue
  814.       fi
  815.       Warn_Autoprobe_Dangerous || continue
  816.       Do_Autoprobe $goal || return 1
  817.       Show_Hardware_Found || continue
  818.       return 0
  819.     fi
  820.     # do not offer new features for COL 1.1 installs
  821.     if [ "`uname -r`" = "2.0.29" ]; then
  822.       Ask string MODULE_PARAM $insmod_params || continue
  823.     else
  824.       Menu_Module_Param "$driver" || continue
  825.     fi
  826.     insmod_params="$ANSWER"
  827.     Do_Load_Module_mini $driver $insmod_params || return 1
  828.     Show_Hardware_Found || continue
  829.     return 0
  830.   done
  831.   return 0
  832. }
  833.  
  834.  
  835. Build_Module_Analyse()
  836. {
  837.   cat << EOF
  838. "BACK" ":MENU_BACK:" \\
  839. "CHECK" ":INFO_HARDWARE_FOUND:" \\
  840. "LOADED" ":MENU_MODULE_SHOW_LOADED:" \\
  841. "SYSINFO" ":MENU_ANALYSE:" \\
  842. "DMESG" ":SHOW_BOOT_MSG:" \\
  843. "REPORT" ":DO_WRITE_ANALYSE_INFOS:" \\
  844. EOF
  845. }
  846.  
  847.  
  848. Menu_Module_Analyse()
  849. {
  850.   local action=CHECK
  851.  
  852.   while [ 1 ]; do
  853.     Ask menu MODULE_ANALYSE --default "$action" Build_Module_Analyse $action || return 1
  854.     action="$ANSWER"
  855.  
  856.     case $action in
  857.     BACK)
  858.       return 0
  859.       ;;
  860.     CHECK)
  861.       Show_Hardware_Found
  862.       ;;
  863.     LOADED)
  864.       Menu_Module_Show_Loaded
  865.       ;;
  866.     SYSINFO)
  867.       Show_Analyse_Info
  868.       ;;
  869.     DMESG)
  870.       Show_Boot_Msg
  871.       ;;
  872.     REPORT) 
  873.       Write_Analyse_Infos
  874.       ;;
  875.     esac
  876.   done
  877. }
  878.  
  879. Build_Module_Load()
  880. {
  881.   local subsys=
  882.  
  883.   echo "\"BACK\" \":MENU_BACK:\" \\"
  884.   for subsys in CD SCSI NET ANY ; do
  885.     echo "\"$subsys\" \":MENU_MODULE_LOAD_$subsys:\" \\"
  886.   done
  887. }
  888.  
  889.  
  890. Menu_Module_Load_mini()
  891. {
  892.   local action
  893.  
  894.   while [ 1 ]; do
  895.     action=
  896.     Ask one MODULE_LOAD --default "$action" Build_Module_Load $action || return 1
  897.     action="$ANSWER"
  898.     if [ "$action" = "BACK" ]; then
  899.       return 0
  900.     fi
  901.     Choose_Module $action || continue
  902.   done
  903. }
  904.  
  905. Build_Modules_Loaded()
  906. {
  907.   echo "\"BACK\" \":MENU_BACK:\" \\"
  908.   cat /proc/modules | do_quote
  909. }
  910.  
  911. Menu_Module_Remove_mini()
  912. {
  913.   Ask one MODULE_REMOVE Build_Modules_Loaded || return 1
  914.   if [ "$ANSWER" = "BACK" ]; then
  915.     return 0
  916.   fi
  917.   /sbin/rmmod $ANSWER || return 1
  918.   return 0
  919. }
  920.  
  921. Build_Config_Modules()
  922. {
  923.   cat << EOF
  924. "DONE" ":MENU_CONFIG_MODULES_DONE:" \\
  925. "ANALYSE" ":MENU_MODULE_ANALYSE:" \\
  926. "LOAD" ":MENU_MODULE_LOAD:" \\
  927. "REMOVE" ":MENU_MODULE_REMOVE:" \\
  928. EOF
  929. }
  930.  
  931.  
  932. Menu_Config_Modules()
  933. {
  934.   local action=CHECK
  935.  
  936.   while [ 1 ]; do
  937.     Ask menu CONFIG_MODULES --default "$action" Build_Config_Modules $action || return 1
  938.     action="$ANSWER"
  939.  
  940.     case $action in
  941.     DONE)
  942.       return 0
  943.       ;;
  944.     ANALYSE)
  945.       Menu_Module_Analyse
  946.       ;;
  947.     LOAD)
  948.       Menu_Module_Load_mini
  949.       ;;
  950.     REMOVE)
  951.       Menu_Module_Remove_mini
  952.       ;;
  953.     esac
  954.   done
  955. }
  956.  
  957. #
  958. # libInit
  959. #
  960.  
  961. InitSubsystems()
  962. {
  963.   local subsys=
  964.   local subsys_state
  965.  
  966.   # If we run from the lisa live filesystem then we skip the first steps
  967.   if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep text`" ]; then
  968.     subsys_state=8
  969.   else
  970.     subsys_state=3
  971.   fi
  972.  
  973.   # first try all subsystems
  974.   rm -f /tmp/subsystems
  975.   for subsys in PCMCIA SCSI NET CD ; do
  976.     echo "$subsys" >> /tmp/subsystems
  977.   done
  978.  
  979.   # load generic 8390 ethernet driver module
  980.   Load_Default_Modules 8390
  981.  
  982.   # load SCSI high level protocol driver
  983.   Load_Default_Modules scsi_mod sd_mod sr_mod st sg
  984.  
  985.   # load filesystems
  986.   Load_Default_Modules nfs isofs
  987.  
  988.   # Only run PCMCIA probing if we are not running from the lisa live filesystem
  989.   if [ -z "`sed -n '/^er=/p' /tmp/cmdline | fgrep text`" ]; then
  990.     # check and load PCMCIA subsystem
  991.     if Is_SPARC ; then
  992.       Debug "Skipping probe for PCMCIA on SPARC!"
  993.     else
  994.       InitPCMCIA
  995.     fi
  996.   fi
  997.  
  998.   while [ 1 ]; do
  999.     subsys_state="`do_calc $subsys_state - 1`"
  1000.     case $subsys_state in
  1001.     0)
  1002.       return 1
  1003.       ;;
  1004.     1)
  1005.       Msg ":ERR_BACKSTEP_NOT_POSSIBLE:"
  1006.       Ask_Bool ABORT_INSTALL y
  1007.       if [ "$ANSWER" = "0" ]; then
  1008.     Do_Reboot
  1009.       fi
  1010.       ;;
  1011.     2)
  1012.       Show_Hardware_Found generic || continue
  1013.       ;;
  1014.     3)
  1015.       Ask_Hardware_Sufficient generic || continue
  1016.       if [ "$ANSWER" = "0" ]; then
  1017.         # this lets us jump to Menu_Config_Modules
  1018.         subsys_state=20
  1019.     continue
  1020.       fi
  1021.       ;;
  1022.     4)
  1023.       Ask_Autoprobe cautious || continue
  1024.       if [ "$ANSWER" != "0" ]; then
  1025.         # this lets us jump to Menu_Config_Modules
  1026.         subsys_state=11
  1027.     continue
  1028.       fi
  1029.       ;;
  1030.     5)
  1031.       Warn_Autoprobe_Dangerous || continue
  1032.       Do_Autoprobe all cautious
  1033.       subsys_state="`do_calc $subsys_state + 1`"
  1034.       ;;
  1035.     6)
  1036.       Msg ":ERR_BACKSTEP_NOT_POSSIBLE:"
  1037.       Ask_Bool ABORT_INSTALL y
  1038.       if [ "$ANSWER" = "0" ]; then
  1039.     Do_Reboot
  1040.       fi
  1041.       ;;
  1042.     7)
  1043.       Show_Hardware_Found || continue
  1044.       ;;
  1045.     8)
  1046.       Ask_Hardware_Sufficient || continue
  1047.       if [ "$ANSWER" = "0" ]; then
  1048.         # this lets us jump to Menu_Config_Modules
  1049.         subsys_state=20
  1050.     continue
  1051.       fi
  1052.       subsys_state="`do_calc $subsys_state + 1`"
  1053.       ;;
  1054.     9)
  1055.       Msg ":ERR_BACKSTEP_NOT_POSSIBLE:"
  1056.       Ask_Bool ABORT_INSTALL y
  1057.       if [ "$ANSWER" = "0" ]; then
  1058.     Do_Reboot
  1059.       fi
  1060.       ;;
  1061.     10)
  1062.       Menu_Config_Modules || continue
  1063.       ;;
  1064.     *)
  1065.       Info ":INFO_WAIT:"
  1066.       Store_Detected_Info
  1067.       # If we run from the lisa live filesystem then bootpc was already run
  1068.       # so we do not have to rerun it but can limit it to reading out results
  1069.       if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep text`" ]; then
  1070.     Read_BOOTP_Info
  1071.       else
  1072.     Get_BOOTP_Info
  1073.       fi
  1074.       return 0
  1075.       ;;
  1076.     esac
  1077.     subsys_state="`do_calc $subsys_state + 2`"
  1078.   done
  1079. }
  1080.  
  1081. #
  1082. # libPCMCIA
  1083. #
  1084.  
  1085. HasPCMCIA()
  1086. {
  1087.   Debug "searching for PCMCIA controllers with probe:"
  1088.   prep_use PCMCIA_PROBE
  1089.   /sbin/probe >/tmp/pcmcia 2>&1
  1090.   if [ $? -eq 0 ]; then
  1091.     Debug "probe returned with 0"
  1092.     Debug "PCMCIA chip found! Asking for PCMCIA Support!"
  1093.     Ask bool PCMCIA_SUPPORT y || return 1
  1094.     if [ "$ANSWER" != "0" ]; then return 1 ; fi
  1095.     MountModulesFloppy
  1096.   else
  1097.     Debug "probe returned with non 0"
  1098.     Debug "No supported PCMCIA chip found! Skipping PCMCIA!"
  1099.     return 1
  1100.   fi
  1101.   return 0
  1102. }
  1103.  
  1104. UnpackPCMCIA()
  1105. {
  1106.   mkdir -p /lib/modules/`uname -r`/pcmcia
  1107.  
  1108.   Debug "Memory usage before PCMCIA unpack:"
  1109.   free > /dev/tty8
  1110.   Debug "disk usage before PCMCIA unpack:"
  1111.   df > /dev/tty8
  1112.  
  1113.   prep_use PCMCIA
  1114.  
  1115.   Debug "Memory usage after PCMCIA unpack:"
  1116.   free > /dev/tty8
  1117.   Debug "disk usage after PCMCIA unpack:"
  1118.   df > /dev/tty8
  1119.   return 0
  1120. }
  1121.  
  1122. RemovePCMCIA()
  1123. {
  1124.   not_use PCMCIA_PROBE
  1125.   not_use PCMCIA
  1126. }
  1127.  
  1128. InitPCMCIA()
  1129. {
  1130.   local pcic=
  1131.   local chip=
  1132.   local modpath=
  1133.   local retval=1
  1134.  
  1135.   if [ -z "`fgrep -x PCMCIA /tmp/subsystems`" ]; then
  1136.     return 0
  1137.   fi
  1138.  
  1139.   modpath=/lib/modules/`uname -r`/pcmcia
  1140.  
  1141.   HasPCMCIA || return 1
  1142.   UnpackPCMCIA || return 1
  1143.  
  1144.   # /bin/sh /etc/rc.d/rc.pcmcia
  1145.   # this will be replaced by rc.pcmcia
  1146.   while [ 1 ]; do
  1147.     Load_Default_Modules pcmcia_core || break
  1148.     # the chip should be derived automatically from the probe command
  1149.     # see /tmp/pcmcia
  1150.     for chip in i82365 tcic ; do
  1151.       Load_Default_Modules $chip
  1152.       if [ $? -eq 0 ]; then
  1153.         pcic=$chip
  1154.         Load_Default_Modules ds
  1155.         break
  1156.       fi
  1157.     done
  1158.     if [ -z "$pcic" ]; then break ; fi
  1159.     if [ ! -s /sbin/cardmgr ]; then break ; fi
  1160.     /sbin/cardmgr || break
  1161.     pcic="ok"
  1162.     break
  1163.   done
  1164.   if [ "$pcic" != "ok" ]; then
  1165.     if [ -z "$pcic" ]; then
  1166.       Debug "No supported PCMCIA chip found! Skipping PCMCIA!"
  1167.     fi
  1168.     if [ -s /var/run/cardmgr.pid ]; then
  1169.       kill `cat /var/run/cardmgr.pid`
  1170.       sleep 1
  1171.     fi
  1172.     /sbin/rmmod ds >/dev/null 2>&1 
  1173.     /sbin/rmmod tcic >/dev/null 2>&1
  1174.     /sbin/rmmod i82365 >/dev/null 2>&1
  1175.     /sbin/rmmod pcmcia_core >/dev/null 2>&1
  1176.   else
  1177.     Debug "$chip PCMCIA chip detected!"
  1178.     Debug "Ask to insert PCMCIA cards"
  1179.     Msg ":DO_INSERT_PCMCIA_CARDS:"
  1180.     retval=0
  1181.   fi
  1182.   # remove all PCMCIA modules from the ramdisk to save space
  1183.   RemovePCMCIA
  1184.   return $retval
  1185. }
  1186.  
  1187. Set_If_Unset()
  1188. {
  1189.     if [ -z "`get_val $1`" ]; then
  1190.         set_val $1 "$2"
  1191.     fi
  1192. }
  1193.  
  1194. Get_netprobe_Info()
  1195. {
  1196.   local retval
  1197.   local probes="`get_val CONF_SETUP_NETPROBE_PROBES`"
  1198.   local probe_hostname
  1199.   local probe_gateway
  1200.   local probe_nameserver
  1201.   local probe_netmask
  1202.   local probe_nisdomain
  1203.   local probe_nisserver
  1204.   local probe_string
  1205.   local bpf=/tmp/netprobe.out
  1206.   local debug_tty
  1207.   local fqhn=
  1208.   local eth0_ip=
  1209.   local eth0_mask=
  1210.   local eth0_bcast=
  1211.   local eth0_net=
  1212.   local router1_ip=
  1213. # local dns_domain=
  1214. # local dns_search=
  1215.   local dns_server1_ip=
  1216. # local dns_server2_ip=
  1217. # local dns_server3_ip=
  1218.   local nfs_server1_ip=
  1219.   local nfs_server1_path=
  1220.   local nis_domain=
  1221.   local nis_server1_ip=
  1222.  
  1223.   # If we run from the lisa live filesystem then use tty4 for debug output
  1224.   if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep text`" ]; then
  1225.     debug_tty=/dev/tty4
  1226.   else
  1227.     debug_tty=/dev/tty7
  1228.   fi
  1229.  
  1230.   if [ "`get_val CONF_SETUP_USE_NETPROBE`" != "on" ]; then return 1 ; fi
  1231.   if [ -z "$probes" ]; then return 1 ; fi
  1232.   if [ ! -x /usr/bin/netprobe ]; then return 1 ; fi
  1233.  
  1234.   Info ":INFO_NETPROBE_RUNNING: ; ; :INFO_WAIT:"
  1235.   sleep 2
  1236.  
  1237.   # building probe_string
  1238.   echo "$probes" | fgrep netmask > /dev/null
  1239.   if [ $? -eq 0 ]; then
  1240.     probe_netmask=true
  1241.     probe_string="$probe_string -p netmask"
  1242.   fi
  1243.   echo "$probes" | fgrep nisdomain > /dev/null
  1244.   if [ $? -eq 0 ]; then
  1245.     probe_nisdomain=true
  1246.     probe_string="$probe_string -p nisdomain"
  1247.   fi
  1248.   echo "$probes" | fgrep nameserver > /dev/null
  1249.   if [ $? -eq 0 ]; then
  1250.     probe_nameserver=true
  1251.     probe_string="$probe_string -p nameserver"
  1252.   fi
  1253.   echo "$probes" | fgrep nisserver > /dev/null
  1254.   if [ $? -eq 0 ]; then
  1255.     probe_nisserver=true
  1256.     probe_string="$probe_string -p nisserver"
  1257.   fi
  1258.   echo "$probes" | fgrep hostname > /dev/null
  1259.   if [ $? -eq 0 ]; then
  1260.     probe_hostname=true
  1261.     probe_string="$probe_string -p hostname"
  1262.   fi
  1263.   echo "$probes" | fgrep gateway > /dev/null
  1264.   if [ $? -eq 0 ]; then
  1265.     probe_gateway=true
  1266.     probe_string="$probe_string -p gateway"
  1267.   fi
  1268.  
  1269.   # remark: lo and eth0 has to be up and running, so the IP address
  1270.   #         has to be known
  1271.  
  1272.   echo "running netprobe..." > $debug_tty
  1273.   /usr/bin/netprobe $probe_string > $bpf 2> $debug_tty
  1274.   retval=$?
  1275.  
  1276.   if [ $retval -ne 0 ]; then
  1277.     echo "netprobe returns with <$retval>" > $debug_tty
  1278.     # return 1
  1279.   fi
  1280.  
  1281.   if [ ! -s $bpf ]; then
  1282.     echo "netprobe returns no output" > $debug_tty
  1283.     return 1
  1284.   fi
  1285.  
  1286.   echo "netprobe returns:" > $debug_tty
  1287.   cat $bpf > $debug_tty
  1288.  
  1289.   while [ 1 ]; do
  1290.     Browse2 $bpf NETPROBE_OUTPUT || return 1
  1291.     Ask_Bool USE_NETPROBE_OUTPUT || continue
  1292.     if [ "$ANSWER" != "0" ]; then return 1 ; fi
  1293.     break
  1294.   done
  1295.  
  1296.   fqhn="`get_val -f $bpf HOSTNAME`"
  1297.   if [ -n "$probe_hostname" -a -n "$fqhn" ]; then
  1298.     Set_If_Unset CONF_FQ_HOSTNAME "$fqhn"
  1299.   fi
  1300.  
  1301.   # FIXME
  1302.   eth0_ip="`get_val CONF_eth0_IP`"
  1303.   eth0_net="`get_val CONF_eth0_NET`"
  1304.  
  1305.   eth0_mask="`get_val -f $bpf NETMASK`"
  1306.   eth0_bcast="`get_val -f $bpf BROADCAST`"
  1307.   if [ -n "$eth0_mask" -a -n "$eth0_ip" -a -n "$probe_netmask" ]; then
  1308.       Set_If_Unset CONF_eth0_MASK "$eth0_mask"
  1309.       Set_If_Unset CONF_eth0_BCAST "$eth0_bcast"
  1310.  
  1311.     # now reconfigure eth0 interface
  1312.     ifconfig eth0 down 2> $debug_tty
  1313.     ifconfig lo down 2> $debug_tty
  1314.     ifconfig lo 127.0.0.1 2> $debug_tty
  1315.     route add -net 127.0.0.0 2> $debug_tty
  1316.     ifconfig eth0 $eth0_ip netmask $eth0_mask broadcast $eth0_bcast 2> $debug_tty
  1317.     route add -net $eth0_net 2> $debug_tty
  1318.   fi
  1319.  
  1320.   router1_ip="`get_val -f $bpf GATEWAY`"
  1321.   if [ -n "$probe_gateway" -a -n "$router1_ip" ]; then
  1322.     Set_If_Unset CONF_ROUTER1_IP "$router1_ip"
  1323.   fi
  1324.  
  1325.   dns_server1_ip="`get_val -f $bpf DNSSERVER1`"
  1326. # dns_server2_ip="`get_val -f $bpf DNSSRVS`"
  1327. # dns_server3_ip="`get_val -f $bpf DNSSRVS`"
  1328.   if [ -n "$probe_nameserver" -a -n "dns_server1_ip" ]; then
  1329.     # Set_If_Unset CONF_DNS_DOMAIN "$dns_domain"
  1330.     # Set_If_Unset CONF_DNS_SEARCH "$dns_search"
  1331.     Set_If_Unset CONF_DNS_SERVER1_IP "$dns_server1_ip"
  1332.     # Set_If_Unset CONF_DNS_SERVER2_IP "$dns_server2_ip"
  1333.     # Set_If_Unset CONF_DNS_SERVER3_IP "$dns_server3_ip"
  1334.   fi
  1335.  
  1336.   nis_domain="`get_val -f $bpf NISDOMAIN`"
  1337.   if [ -n "$probe_nisdomain" -a -n "$nis_domain" ]; then
  1338.     Set_If_Unset CONF_NIS_DOMAIN "$nis_domain"
  1339.   fi
  1340.  
  1341.   nis_server1_ip="`get_val -f $bpf NISSERVER1 | cut -d':' -f 1`"
  1342.   if [ -n "$probe_nisserver" -a -n "$nis_server1_ip" ]; then
  1343.     Set_If_Unset CONF_NIS_SERVER1_IP "$nis_server1_ip"
  1344.   fi
  1345.  
  1346. # Set_If_Unset CONF_NFS_SERVER1_IP "$nfs_server1_ip"
  1347. # Set_If_Unset CONF_NFS_SERVER1_PATH "$nfs_server1_path"
  1348. }
  1349.  
  1350. Read_BOOTP_Info()
  1351. {
  1352.   local bpf=/tmp/bootpc.out
  1353.   local debug_tty=/dev/tty4
  1354.   local fqhn=
  1355.   local eth0_ip=
  1356.   local eth0_mask=
  1357.   local eth0_bcast=
  1358.   local router1_ip=
  1359. # local dns_domain=
  1360. # local dns_search=
  1361.   local dns_server1_ip=
  1362. # local dns_server2_ip=
  1363. # local dns_server3_ip=
  1364.   local nfs_server1_ip=
  1365.   local nfs_server1_path=
  1366.   local nis_domain=
  1367.   local nis_server1_ip=
  1368.  
  1369.   if [ ! -s $bpf ]; then
  1370.     echo "bootpc returns no output" > $debug_tty
  1371.     return 1
  1372.   fi
  1373.  
  1374.   echo "bootpc returns:" > $debug_tty
  1375.   cat $bpf > $debug_tty
  1376.  
  1377.   while [ 1 ]; do
  1378.     Browse2 $bpf BOOTP_OUTPUT || return 1
  1379.     Ask_Bool USE_BOOTP_OUTPUT || continue
  1380.     if [ "$ANSWER" != "0" ]; then return 1 ; fi
  1381.     break
  1382.   done
  1383.  
  1384.   fqhn="`get_val -f $bpf HOSTNAME`"
  1385.   eth0_ip="`get_val -f $bpf IPADDR`"
  1386.   eth0_mask="`get_val -f $bpf NETMASK`"
  1387.   eth0_bcast="`get_val -f $bpf BROADCAST`"
  1388.   router1_ip="`get_val -f $bpf GATEWAYS | sed 's/ .*//'`"
  1389.   dns_server1_ip="`get_val -f $bpf DNSSRVS | sed 's/ .*//'`"
  1390. # dns_server2_ip="`get_val -f $bpf DNSSRVS`"
  1391. # dns_server3_ip="`get_val -f $bpf DNSSRVS`"
  1392.   nis_domain="`get_val -f $bpf NISDOMAIN`"
  1393.   nis_server1_ip="`get_val -f $bpf NISSERVER | sed 's/ .*//'`"
  1394.  
  1395.   set_val CONF_FQ_HOSTNAME "$fqhn"
  1396.   set_val CONF_eth0_IP "$eth0_ip"
  1397.   set_val CONF_eth0_MASK "$eth0_mask"
  1398.   set_val CONF_eth0_BCAST "$eth0_bcast"
  1399.   set_val CONF_ROUTER1_IP "$router1_ip"
  1400.   Set_If_Unset CONF_NFS_SERVER1_IP "$nfs_server1_ip"
  1401.   Set_If_Unset CONF_NFS_SERVER1_PATH "$nfs_server1_path"
  1402. # set_val CONF_DNS_DOMAIN "$dns_domain"
  1403. # set_val CONF_DNS_SEARCH "$dns_search"
  1404.   set_val CONF_DNS_SERVER1_IP "$dns_server1_ip"
  1405. # set_val CONF_DNS_SERVER2_IP "$dns_server2_ip"
  1406. # set_val CONF_DNS_SERVER3_IP "$dns_server3_ip"
  1407.   set_val CONF_NIS_DOMAIN "$nis_domain"
  1408.   set_val CONF_NIS_SERVER1_IP "$nis_server1_ip"
  1409. }
  1410.  
  1411.  
  1412. Get_BOOTP_Info()
  1413. {
  1414.   local retval
  1415.   local bpf=/tmp/bootpc.out
  1416.   local debug_tty=/dev/tty4
  1417.  
  1418.   if [ "`get_val CONF_SETUP_USE_BOOTP`" != "on" ]; then return 1 ; fi
  1419.   if [ ! -x /usr/bin/bootpc ]; then return 1 ; fi
  1420.  
  1421.   Info ":INFO_BOOTP_RUNNING: ; ; :INFO_WAIT:"
  1422.   sleep 2
  1423.   
  1424.   ifconfig eth0 down 2> $debug_tty
  1425.   ifconfig lo down 2> $debug_tty
  1426.  
  1427.   ifconfig lo 127.0.0.1 2> $debug_tty
  1428.   route add -net 127.0.0.0 2> $debug_tty
  1429.   ifconfig eth0 0.0.0.0 netmask 0.0.0.0 broadcast 0.0.0.0 2> $debug_tty
  1430.   route add -net 0.0.0.0 2> $debug_tty
  1431.  
  1432.   echo "running bootpc..." > $debug_tty
  1433.   /usr/bin/bootpc > $bpf 2> $debug_tty
  1434.   retval=$?
  1435.  
  1436.   ifconfig eth0 down 2> $debug_tty
  1437.   ifconfig lo down 2> $debug_tty
  1438.  
  1439.   if [ $retval -ne 0 ]; then
  1440.     echo "bootpc returns with <$retval>" > $debug_tty
  1441.     return 1
  1442.   fi
  1443.  
  1444.   Read_BOOTP_Info
  1445. }
  1446.  
  1447.  
  1448. #######################################################################
  1449.  
  1450. # libLSTcheck check functions shared between several scripts
  1451. #
  1452. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  1453. #
  1454.  
  1455. # check arguments for a function
  1456. #
  1457. Check_Args()
  1458. {
  1459.   if [ $# -lt 3 ]; then
  1460.     Panic "Check_Args :ERR_WRONG_NUM_OF_ARGS: ($#)"
  1461.     Panic "function Check_Args (wanted 4 args, got $# args) ; args=<$@> ; :ERR_WRONG_NUM_OF_ARGS:"
  1462.     return 1
  1463.   fi
  1464.   if [ $2 -ne $3 ]; then
  1465.     Panic "function $1 (wanted $2 args, got $3 args) ; args=<$4> ; :ERR_WRONG_NUM_OF_ARGS:"
  1466.     return 1
  1467.   fi
  1468.   return 0
  1469. }
  1470.  
  1471. # test a string against a valid char list
  1472. # returns 0 if all chars of string are in the valid_char_list
  1473. # returns 1 if invalid chars are found and echos invalid chars
  1474. #
  1475. Check_Chars_Valid()
  1476. {
  1477.     local f_name=Check_Chars_Valid
  1478.     local f_args=2 # (string, validchars) ->
  1479.  
  1480.     Check_Args $f_name $f_args $# "$@" || return 255
  1481.     # Test for invalid chars
  1482.     dummy=`echo $1 | sed "s/[$2]//g"`
  1483.     if [ ! -z "$dummy" ]; then
  1484.         echo "$dummy"
  1485.         return 1
  1486.     else
  1487.         return 0
  1488.     fi
  1489. }
  1490.  
  1491. Check_Chroot()
  1492. {
  1493.     if [ "$DIR_TARGET" != "/" ]; then
  1494.         $CMD_BOX --title ":WARNING:" --msg "$1 ; :ERR_IMPOSSIBLE_WITH_CHROOT:"
  1495.         return 1
  1496.     fi
  1497.     return 0
  1498. }
  1499.  
  1500. Is_Expert()
  1501. {
  1502.     local f_name=Is_Expert
  1503.     local f_args=0 # MODE_USER ->
  1504.  
  1505.     Check_Args $f_name $f_args $# "$@" || return 255
  1506.     if [ "$MODE_USER" = "expert" ]; then
  1507.         return 0
  1508.     else
  1509.         return 1
  1510.     fi
  1511. }
  1512.  
  1513. Has_File()
  1514. {
  1515.     if [ $# -lt 1 ]; then
  1516.         Panic "missing arg to Has_File"
  1517.     fi
  1518.     if [ -s $1 ]; then
  1519.         return 0
  1520.     else
  1521.         if [ -f $1 ]; then
  1522.             Debug "$f_name: $1: file is empty."
  1523.         else
  1524.             Debug "$f_name: $1: file is not installed."
  1525.             if [ $# -gt 1 ]; then
  1526.                 Error "$2"
  1527.             fi
  1528.         fi
  1529.         return 1
  1530.     fi
  1531. }
  1532.  
  1533. # check if a file exists
  1534. #
  1535. Check_File()
  1536. {
  1537.   local f_name=Check_File
  1538.   local f_args=1 # (file) ->
  1539.  
  1540.   Check_Args $f_name $f_args $# "$@" || return 255
  1541.   if [ -f $1 ]; then
  1542.     return 0
  1543.   else
  1544.     return 1
  1545.   fi
  1546. }
  1547.  
  1548. # search for a string (exact match) in a file
  1549. #
  1550. Check_Found()
  1551. {
  1552.     local f_name=Check_Found
  1553.     local f_args=2 # (string, file) ->
  1554.  
  1555.     Check_Args $f_name $f_args $# "$@" || return 255
  1556.     if [ -z "$1" ]; then
  1557.         Debug "Check_Found: arg 1 is empty"
  1558.         return 2
  1559.     fi
  1560.     if [ -z "$2" ]; then
  1561.         Debug "Check_Found: arg 2 is empty"
  1562.         return 3
  1563.     fi
  1564.     if [ ! -s $2 ]; then
  1565.         Debug "Check_Found: $2: file empty or nonexistent"
  1566.         return 4
  1567.     fi
  1568.     fgrep -x $1 $2 >/dev/null 2>&1 || return 1
  1569.     return 0
  1570. }
  1571.  
  1572. # checks if a path is valid and sets STATUS to the type and
  1573. # and if false ERROR to an error message
  1574. #
  1575. Check_Path_Valid()
  1576. {
  1577.     local f_name=Check_Path_Valid
  1578.     local f_args=1 # (path) -> STATUS,ERROR
  1579.     export STATUS=
  1580.     export ERROR=
  1581.  
  1582.     Check_Args $f_name $f_args $# "$@" || return 255
  1583.     if [ -L $1 ]; then
  1584.         STATUS="symlink"
  1585.     elif [ -d $1 ]; then
  1586.         STATUS="directory"
  1587.     elif [ -f $1 ]; then
  1588.         STATUS="file"
  1589.     else
  1590.         ERROR="$1 ; :ERR_INVALID_PATH:"
  1591.         return 1
  1592.     fi
  1593.     return 0
  1594. }
  1595.  
  1596. # Call action_func and depending on success the corresponding func
  1597. #
  1598. Do_Action()
  1599. {
  1600.     local f_name=Do_Action
  1601.     local f_args=3 # (action_func, success_func, error_func) ->
  1602.  
  1603.     Check_Args $f_name $f_args $# "$@" || return 255
  1604.     eval $1
  1605.     if [ $? -eq 0 ]; then
  1606.         eval $2
  1607.         return 0
  1608.     else
  1609.         eval $3
  1610.         return 1
  1611.     fi
  1612. }
  1613.  
  1614. Do_Analyse_All()
  1615. {
  1616.     sysinfo --var > $FILE_TMP_MSG.tmp 2> $FILE_BOOT_DIAG.tmp 
  1617.     sed -e 's/ sr=/ scd=/g' -e 's:/dev/sr:/dev/scd:g' < $FILE_TMP_MSG.tmp > $FILE_TMP_MSG
  1618.     sed -e 's/:sr=/:scd=/g' -e 's:/dev/sr:/dev/scd:g' < $FILE_BOOT_DIAG.tmp > $FILE_BOOT_DIAG
  1619.     rm -f $FILE_BOOT_DIAG.tmp $FILE_TMP_MSG.tmp
  1620.     sleep 2
  1621. }
  1622.  
  1623. Do_Backup_File()
  1624. {
  1625.   local file=$1
  1626.  
  1627.   if [ -f $file ]; then
  1628.     cp -a $file ${file}~
  1629.   fi
  1630. }
  1631.  
  1632.  
  1633. #
  1634. # filter right edition from libLSTall
  1635. #
  1636. Do_Filter_libLSTall()
  1637. {
  1638.   local edition=$1
  1639.   local omit=
  1640.  
  1641.   case $edition in
  1642.   CND)
  1643.     omit="LST"
  1644.     ;;
  1645.   *)
  1646.     omit="CND"
  1647.     ;;
  1648.   esac
  1649.  
  1650.   sed -e '/^#%#ifdef '$omit'/,/^#%#endif '$omit'/d' \
  1651.     -e '/^#%#/d'
  1652. }
  1653.  
  1654.  
  1655. #
  1656. # filter right language and edition from libLSTtext
  1657. #
  1658. Do_Filter_libLSTtext()
  1659. {
  1660.   local edition=$1
  1661.   local lang=$2
  1662.   sed "{
  1663.     s/^${lang}-$edition> //
  1664.     s/^${lang}-x> //
  1665.     s/^x-$edition> //
  1666.     s/^x-x> //
  1667.     /^[a-z]\{2\}-[A-Za-z]\{3,5\}> /d
  1668.         /^x-[A-Za-z]\{3,5\}> /d
  1669.     /^[a-z]\{2\}-x> /d
  1670.     }"
  1671. }
  1672.  
  1673. Do_Merge_libLSTtext()
  1674. {
  1675.     local floppy_lib="$1"
  1676.     local cd_lib="$2"
  1677.     local labels_new="ASK_ETHER_REMOTE_IP_TEXT ASK_ETHER_REMOTE_IP_TITLE TYPE_CD_arcd TYPE_CD_bpcd TYPE_CD_bpmcd TYPE_CD_dscd TYPE_CD_eicd TYPE_CD_epcd TYPE_CD_kicd TYPE_CD_oicd TYPE_CD_pwcd TYPE_PARALLEL_DEV_lp0 TYPE_PARALLEL_DEV_lp1 TYPE_PARALLEL_DEV_lp2 TYPE_PRINTER_PostScript"
  1678.     local label
  1679.  
  1680.     # the libLSTtext-mini on the floppy is more up to date
  1681.     # and also may contain labels the libLSTtext CD version
  1682.     # doesn't have.
  1683.     # The trick is to keep what's in the mini version only
  1684.     # and to append the CD version
  1685.  
  1686.     # if they are the same, then take the one from the CD
  1687.     if [ "`sed -n '/^# $Id/p' $floppy_lib`" = "`sed -n '/^# $Id/p' $cd_lib`" ]; then
  1688.         cp -a $cd_lib $floppy_lib
  1689.         return 0
  1690.     fi
  1691.  
  1692.     # otherwise take the floppy header
  1693.     sed -n '1,/^:/{
  1694.         /^:/d
  1695.         p
  1696.         }' $floppy_lib > ${floppy_lib}.new
  1697.     # add the new labels
  1698.     for label in $labels_new ; do
  1699.         sed -n "/^:$label:/,/^:/{
  1700.             /^:$label:/p
  1701.             /^:/d
  1702.             p
  1703.             }" $floppy_lib >> ${floppy_lib}.new
  1704.     done
  1705.     # and append the old CD version
  1706.     cat $cd_lib >> ${floppy_lib}.new
  1707.     mv ${floppy_lib}.new $floppy_lib
  1708.     return 0
  1709. }
  1710.  
  1711. # try to lookup a short filename for a given long filename
  1712. # by a 'trans.tbl' file
  1713. #
  1714. Do_Lookup_Trans_Tbl()
  1715. {
  1716.   local dir="`dirname $1`"
  1717.   local TransTblFile="$dir/trans.tbl"
  1718.   local LongName="`basename $1`"
  1719.   local PkgRegexProof="`echo "$LongName" | sed 's/\+/\\\+/g'`"
  1720.   local ShortName=
  1721.  
  1722.   Debug "Called Do_Lookup_Trans_Tbl $1"
  1723.   if [ ! -f $TransTblFile ]; then
  1724.     Debug "trans.tbl file $TransTblFile not found"
  1725.     return 1
  1726.   fi
  1727.  
  1728.   # using cut to circumvent broken sed
  1729.   ShortName="`sed -n '/[     ]'${PkgRegexProof}'$/p' $TransTblFile | cut -c 3-14`"
  1730.   Debug "ShortName=<$ShortName>"
  1731.   if [ ! -z "$ShortName" -a -r "$dir/$ShortName" ]; then
  1732.     export ANSWER="$dir/$ShortName"
  1733.     return 0
  1734.   fi
  1735.   return 1
  1736. }
  1737.  
  1738. Do_Clear_Screen()
  1739. {
  1740.     echo "c"
  1741. }
  1742.  
  1743. # Do_Config_Update ( CONFIG_FILE )
  1744. #
  1745. #    Reset config file with current values
  1746. #
  1747. Do_Config_Update()
  1748. {
  1749.     # Wipe out old configuration and prepare new    
  1750.     ( sed -n "
  1751.         /^$/ {
  1752.             s/^/echo/p
  1753.             d
  1754.         }
  1755.         /^#/ {
  1756.             s/^\(.*\)/echo \'\1\'/p
  1757.             d
  1758.         }
  1759.         s/^\(.*\)=\(.*\)/echo \"\1=\$\1\"/p
  1760.     " ) < $1 > $1.$$.tmp
  1761.     if [ $? != 0 ]; then
  1762.         Panic "Do_Config_Update: error in sed call"
  1763.         return 1
  1764.     fi
  1765.  
  1766.     # Analyse system to get valid settings
  1767.     # Analyse_System -all
  1768.  
  1769.     # Erase old config file
  1770.     . $1.$$.tmp >> $1.$$.tmp2
  1771.     rm -f $1.$$.tmp
  1772.     # Requote Variables
  1773.     sed '/^[^#]/s/^\(.*\)=\(.*\)/\1=\"\2\"/' < $1.$$.tmp2 > $1
  1774.     rm -f $1.$$.tmp2
  1775. }
  1776.  
  1777. Do_Prompt()
  1778. {
  1779.     echo -n "press any key to continue"
  1780.     get_key > /dev/null
  1781.     echo
  1782. }
  1783.  
  1784. # Do_Store ( VAR VAL [CONFIG_FILE] )
  1785. #
  1786. Do_Store()
  1787. {
  1788.     local conf_file=$FILE_SYSTEM_CONF
  1789.  
  1790.     if [ $# -eq 3 ]; then
  1791.         conf_file=$3
  1792.     elif [ $# -ne 2 ]; then
  1793.         Panic "got $# instead of 2 or 3 args!"
  1794.     fi
  1795.  
  1796.     # store in config file
  1797.     set_val -f $conf_file "$1" "$2"
  1798.     echo "$1=\"$2\"" > $FILE_TMP_VAL
  1799.     . $FILE_TMP_VAL
  1800.     rm -f $FILE_TMP_VAL
  1801. }
  1802.  
  1803. Do_Symlink()
  1804. {
  1805.     local f_name=Do_Symlink
  1806.     local f_args=2 # (orig, symlink) ->
  1807.     local dir1
  1808.     local dir2
  1809.     local file1
  1810.     local file2
  1811.  
  1812.     Check_Args $f_name $f_args $# "$@" || return 255
  1813.     dir1="`dirname $1`"
  1814.     dir2="`dirname $2`"
  1815.     file1="`basename $1`"
  1816.     file2="`basename $2`"
  1817.  
  1818.     if [ ! -d $DIR_TARGET/$dir1 ]; then
  1819.         mkdir -p $DIR_TARGET/$dir1
  1820.     fi
  1821.  
  1822.     if [ ! -d $DIR_TARGET/$dir2 ]; then
  1823.         mkdir -p $DIR_TARGET/$dir2
  1824.     fi
  1825.     if [ "$dir1" = "$dir2" ]; then
  1826.         ( cd $DIR_TARGET/$dir2 ; ln -sf $file1 $file2 )
  1827.     else
  1828.         ( cd $DIR_TARGET/$dir2 ; ln -sf $1 $file2 )
  1829.     fi
  1830. }
  1831.  
  1832. # Do_Translate STRING [DICTIONARY]
  1833. #
  1834. Do_Translate()
  1835. {
  1836.   local my_lang="`get_val CONF_LST_LANG`"
  1837.   local dict=/usr/lib/LST/$my_lang/libLSTtext
  1838.  
  1839.   if [ $# -gt 1 ]; then
  1840.     dict="$2"
  1841.   fi
  1842.  
  1843.   $CMD_BOX -t --dictionary $dict --text "$1"
  1844. }
  1845.  
  1846. Get_Val()
  1847. {
  1848.     if [ $# -gt 1 ]; then
  1849.         get_val -d "$2" -f $FILE_SYSTEM_CONF "$1"
  1850.     else
  1851.         get_val -f $FILE_SYSTEM_CONF "$1"
  1852.     fi
  1853. }
  1854.  
  1855. Show_Analyse_Info()
  1856. {
  1857.     Do_Analyse_All
  1858.     Browse2 $FILE_TMP_MSG ANALYSE || return 1
  1859.     return 0
  1860. }
  1861.  
  1862. Show_Hardware_Info()
  1863. {
  1864.     Do_Analyse_All
  1865.     sysinfo --hardware > $FILE_TMP_MSG
  1866.     Browse2 $FILE_TMP_MSG ANALYSE || return 1
  1867.     return 0
  1868. }
  1869.  
  1870. Show_Kernel_Info()
  1871. {
  1872.     Do_Analyse_All
  1873.     sysinfo --kernel > $FILE_TMP_MSG
  1874.     Browse2 $FILE_TMP_MSG ANALYSE || return 1
  1875.     return 0
  1876. }
  1877.  
  1878. Show_Partition_Info()
  1879. {
  1880.     Do_Analyse_All
  1881.     sysinfo --partition > $FILE_TMP_MSG
  1882.     Browse2 $FILE_TMP_MSG ANALYSE || return 1
  1883.     return 0
  1884. }
  1885.  
  1886. Show_System_Info()
  1887. {
  1888.     Do_Analyse_All
  1889.     sysinfo --system > $FILE_TMP_MSG
  1890.     Browse2 $FILE_TMP_MSG ANALYSE || return 1
  1891. }
  1892.  
  1893. # libLSTconfig - configuration library shared between several scripts
  1894. #
  1895. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  1896. #
  1897.  
  1898. Menu_Config_Tape()
  1899. {
  1900.     local tape
  1901.     Choose --none --other --menutitle ":CHOOSE_TAPE_DEV_MENUTITLE:" TAPE_DEV CONF_TAPE1_DEV || return 1
  1902.     tape="$ANSWER"
  1903.     Do_Store CONF_TAPE1_DEV "$tape"
  1904.     if [ -n "$tape" ]; then
  1905.         Do_Symlink $tape /dev/tape
  1906.         Do_Load_Driver tape $tape || return 1
  1907.     fi
  1908.     ANSWER="$tape"
  1909.     return 0
  1910. }
  1911.  
  1912. Menu_Config_CD()
  1913. {
  1914.     local cdrom=
  1915.  
  1916.     if [ "`get_val -f /etc/lst.cnf CONF_COL_EDITION`" = "SBA" ]; then
  1917.         ANSWER="`get_val CONF_CD1_DEV`"
  1918.         if [ -z "$ANSWER" ]; then
  1919.             Choose --none --other --menutitle ":CHOOSE_CD_DEV_MENUTITLE:" CD_DEV CONF_CD1_DEV || return 1
  1920.         fi
  1921.     else
  1922.         Choose --none --other --menutitle ":CHOOSE_CD_DEV_MENUTITLE:" CD_DEV CONF_CD1_DEV || return 1
  1923.     fi
  1924.     cdrom="$ANSWER"
  1925.     Do_Store CONF_CD1_DEV "$cdrom"
  1926.     if [ -n "$cdrom" ]; then
  1927.         Do_Symlink $cdrom /dev/cdrom
  1928.         Do_Load_Driver filesystem iso9660 || return 1
  1929.         Do_Load_Driver cdrom $cdrom || return 1
  1930.     fi
  1931.     ANSWER="$cdrom"
  1932.     return 0
  1933. }
  1934.  
  1935. Build_KEYBOARD()
  1936. {
  1937.     cat << EOF
  1938. "us.map"            ":TYPE_KEYBOARD_US:" \\
  1939. "uk.map"            ":TYPE_KEYBOARD_UK:" \\
  1940. "de-latin1-nodeadkeys.map"    ":TYPE_KEYBOARD_GERMAN:" \\
  1941. "fr-latin1.map"            ":TYPE_KEYBOARD_FRENCH:" \\
  1942. "it.map"            ":TYPE_KEYBOARD_ITALIAN:" \\
  1943. "fi-latin1.map"            ":TYPE_KEYBOARD_FINISH:" \\
  1944. "es.map"            ":TYPE_KEYBOARD_SPANISH:" \\
  1945. "br.map"            ":TYPE_KEYBOARD_BRAZILIAN_PORTUGUESE:" \\
  1946. EOF
  1947. }
  1948.  
  1949. Menu_Config_Keyboard()
  1950. {
  1951.     Check_Chroot ":MENU_CONFIG_KEYBOARD:" || return 1
  1952.     while [ 1 ]; do
  1953.         Choose KEYBOARD CONF_KEYBOARD_MAP || return 1
  1954.         CONF_KEYBOARD_MAP="$ANSWER"
  1955.         if [ ! -f /usr/lib/kbd/keytables/$ANSWER ]; then
  1956.             if [ -f /usr/lib/kbd/keytables/${ANSWER}.gz ]; then
  1957.                 gzip -df /usr/lib/kbd/keytables/${ANSWER}.gz
  1958.             else
  1959.                 $CMD_BOX --msg "$ANSWER ; :ERR_KEYMAP_NOT_AVAILABLE:"
  1960.                 continue
  1961.             fi
  1962.         fi
  1963.         # save old keymap
  1964.         dumpkeys > $DIR_LST_TMP/keymap.old
  1965.         loadkeys $CONF_KEYBOARD_MAP > /dev/null 2>&1
  1966.         $CMD_BOX --string ":DO_TEST_KEYMAP:" 2> $FILE_TMP_ANSWER
  1967.         $CMD_BOX --bool ":ASK_KEEP_KEYMAP:" 2> $FILE_TMP_ANSWER || return 1
  1968.         ANSWER="`cat $FILE_TMP_ANSWER`"
  1969.         if [ $ANSWER -eq 0 ]; then
  1970.             break
  1971.         else
  1972.             loadkeys $DIR_LST_TMP/keymap.old > /dev/null 2>&1
  1973.             rm -f $DIR_LST_TMP/keymap.old
  1974.             continue
  1975.         fi
  1976.     done
  1977.     Do_Store CONF_KEYBOARD_MAP "$CONF_KEYBOARD_MAP"
  1978.     Set_keyboard
  1979. }
  1980.  
  1981. Do_Setup_Modem()
  1982. {
  1983.     local dev=
  1984.     local speed=
  1985.     local type=
  1986.     local faxid=
  1987.  
  1988.     # re-read values
  1989.     dev="`Get_Val CONF_MODEM1_DEV`"
  1990.     speed="`Get_Val CONF_MODEM1_SPEED`"
  1991.     type="`Get_Val CONF_MODEM1_TYPE`"
  1992.     faxid="`Get_Val CONF_MODEM1_FAXID`"
  1993.  
  1994.     if [ -z "$dev" ]; then
  1995.         return 0
  1996.     fi
  1997.  
  1998.     # setup mgetty
  1999.     if [ -f $FILE_MGETTY_CONF ]; then
  2000.         rm -f $FILE_MGETTY_CONF.tmp
  2001.         touch $FILE_MGETTY_CONF.tmp
  2002.         chmod 600 $FILE_MGETTY_CONF.tmp
  2003.         sed "{
  2004.             s/^fax-id.*$/fax-id $faxid/
  2005.             s/^speed.*$/speed $speed/
  2006.             }" $FILE_MGETTY_CONF >> $FILE_MGETTY_CONF.tmp
  2007.         mv $FILE_MGETTY_CONF.tmp $FILE_MGETTY_CONF
  2008.     fi
  2009.     # setup sendfax
  2010.     if [ -f $FILE_SENDFAX_CONF ]; then
  2011.         rm -f $FILE_SENDFAX_CONF.tmp
  2012.         touch $FILE_SENDFAX_CONF.tmp
  2013.         chmod 600 $FILE_SENDFAX_CONF.tmp
  2014.         sed "{
  2015.             s%^fax-id.*$%fax-id $faxid%
  2016.             s%^fax-devices.*$%fax-devices $dev%
  2017.             }" $FILE_SENDFAX_CONF >> $FILE_SENDFAX_CONF.tmp
  2018.         mv $FILE_SENDFAX_CONF.tmp $FILE_SENDFAX_CONF
  2019.     fi
  2020.     # setup symlink
  2021.     Do_Symlink $dev /dev/modem
  2022. }
  2023.  
  2024. Build_MODEM()
  2025. {
  2026.     cat << EOF
  2027. ""        ":TYPE_MODEM_NONE:" \\
  2028. "Hayes"        ":TYPE_MODEM_HAYES:" \\
  2029. "Zyxel"        ":TYPE_MODEM_ZYXEL:" \\
  2030. "Rockwell"    ":TYPE_MODEM_ROCKWELL:" \\
  2031. "Hayes"        ":TYPE_MODEM_UNKNOWN:" \\
  2032. EOF
  2033. }
  2034.  
  2035. Menu_Config_Modem()
  2036. {
  2037.   local type=
  2038.   local dev=
  2039.   local speed=
  2040.   local faxid=
  2041.  
  2042.   while [ 1 ]; do
  2043.     Choose MODEM CONF_MODEM1_TYPE CONF_MODEM1_TYPE || return 1
  2044.     type="$ANSWER"
  2045.     if [ -z "$type" ]; then
  2046.       dev=
  2047.       speed=
  2048.       type=
  2049.       faxid=
  2050.       rm -f /dev/modem
  2051.     else
  2052.       Choose --other --menutitle ":CHOOSE_SERIAL_DEV_MENUTITLE:" SERIAL_DEV CONF_MODEM1_DEV || continue
  2053.       dev="$ANSWER"
  2054.       if [ "$dev" = "`Get_Val CONF_MOUSE1_DEV`" ]; then
  2055.     Warn ":WARN_MOUSE_MODEM_DEV_CONFLICT:" || continue
  2056.       fi
  2057.       if [ "$dev" = "`Get_Val CONF_PRINTER1_DEV`" ]; then
  2058.     Warn ":WARN_MODEM_PRINTER_DEV_CONFLICT:" || continue
  2059.       fi
  2060.       Choose SERIAL_SPEED CONF_MODEM1_SPEED || continue
  2061.       speed="$ANSWER"
  2062.       if [ -f $FILE_SENDFAX_CONF ]; then
  2063.     faxid="`Get_Val CONF_MODEM1_FAXID`"
  2064.     Ask_String MODEM_FAXID "$faxid" || continue
  2065.     faxid="$ANSWER"
  2066.       fi
  2067.     fi
  2068.     Do_Store CONF_MODEM1_DEV "$dev"
  2069.     Do_Store CONF_MODEM1_SPEED "$speed"
  2070.     Do_Store CONF_MODEM1_TYPE "$type"
  2071.     Do_Store CONF_MODEM1_FAXID "$faxid"
  2072.     Do_Setup_Modem
  2073.     return 0
  2074.   done
  2075. }
  2076.  
  2077. Build_MOUSE()
  2078. {
  2079.     if Is_SPARC ; then
  2080.         cat << EOF
  2081. "Sun standard /dev/sunmouse"        ":TYPE_MOUSE_SUN:" \\
  2082. EOF
  2083.     else
  2084.         cat << EOF
  2085. "PS2 ps/2 /dev/psaux"            ":TYPE_MOUSE_PS2_BUS:" \\
  2086. "MouseMan mmseries serial"        ":TYPE_MOUSE_MOUSEMAN_SERIAL:" \\
  2087. "Microsoft microsoft serial"        ":TYPE_MOUSE_MICROSOFT_SERIAL:" \\
  2088. "Microsoft busmouse /dev/bmousems"    ":TYPE_MOUSE_MICROSOFT_BUS:" \\
  2089. "Logitech logitech serial"        ":TYPE_MOUSE_LOGITECH_SERIAL:" \\
  2090. "Logitech busmouse /dev/bmouselogitec"    ":TYPE_MOUSE_LOGITECH_BUS:" \\
  2091. "MouseSystems mousesystems serial"    ":TYPE_MOUSE_MOUSESYSTEMS_SERIAL:" \\
  2092. "ATI_XL busmouse /dev/bmouseatixl"    ":TYPE_MOUSE_ATI_BUS:" \\
  2093. EOF
  2094.     fi
  2095.     cat << EOF
  2096. ""                    ":TYPE_MOUSE_NONE:" \\
  2097. EOF
  2098. }
  2099.  
  2100. Menu_Config_Mouse()
  2101. {
  2102.   local type=
  2103.   local xtype=
  2104.   local dev=
  2105.   local buttons=
  2106.  
  2107.   while [ 1 ]; do
  2108.     Choose MOUSE || return 1
  2109.     if [ -z "$ANSWER" ]; then
  2110.       buttons=
  2111.       dev=
  2112.       type=
  2113.       xtype=
  2114.     else
  2115.       read type xtype dev << EOF
  2116. $ANSWER
  2117. EOF
  2118.       if [ "$dev" = "serial" ]; then
  2119.     Choose --other --menutitle ":CHOOSE_SERIAL_DEV_MENUTITLE:" SERIAL_DEV CONF_MOUSE1_DEV || continue
  2120.     dev="$ANSWER"
  2121.     if [ "$dev" = "`Get_Val CONF_MODEM1_DEV`" ]; then
  2122.       Warn ":WARN_MOUSE_MODEM_DEV_CONFLICT:" || continue
  2123.     fi
  2124.     if [ "$dev" = "`Get_Val CONF_PRINTER1_DEV`" ]; then
  2125.       Warn ":WARN_MOUSE_PRINTER_DEV_CONFLICT:" || continue
  2126.     fi
  2127.       fi    
  2128.       Do_Symlink $dev /dev/mouse
  2129.     fi
  2130.     Do_Store CONF_MOUSE1_BUTTONS "$buttons"
  2131.     Do_Store CONF_MOUSE1_DEV "$dev"
  2132.     Do_Store CONF_MOUSE1_TYPE "$type"
  2133.     Do_Store CONF_MOUSE1_X_TYPE "$xtype"
  2134.     if [ -n "$xtype" -a "$DIR_TARGET" = "/" ]; then
  2135.       Do_Setup_X
  2136.     fi
  2137.     return 0
  2138.   done
  2139. }
  2140.  
  2141. Build_PRINTER_DEV()
  2142. {
  2143.   List box PARALLEL_DEV
  2144.   List box USB_PRINTER_DEV
  2145.   List box SERIAL_DEV
  2146. }
  2147.  
  2148. Start_unconfigured_sh()
  2149. {
  2150.   local uconfsh=/etc/rc.d/unconfigured.sh
  2151.   
  2152.   echo '#!/bin/sh' > $DIR_TARGET/$uconfsh
  2153.   echo "echo -n \"Updating databases:\" " >> $DIR_TARGET/$uconfsh
  2154. }
  2155.  
  2156. Finish_unconfigured_sh()
  2157. {
  2158.     local uconfsh=/etc/rc.d/unconfigured.sh
  2159.  
  2160.     echo 'if [ -x /usr/bin/mandb ]; then ' >> $DIR_TARGET/$uconfsh
  2161.     echo "echo -n \" mandb\" " >> $DIR_TARGET/$uconfsh
  2162.     echo '/usr/bin/mandb -c > /tmp/mandb.log 2>&1 & ' >> $DIR_TARGET/$uconfsh
  2163.     echo 'fi' >> $DIR_TARGET/$uconfsh
  2164.     echo "echo" >> $DIR_TARGET/$uconfsh
  2165.     # append finish.sh downloaded from TFTP Server (auto install mode only)
  2166.     if [ -f /etc/rc.d/finish.sh ]; then
  2167.         cat /etc/rc.d/finish.sh >> $DIR_TARGET/$uconfsh
  2168.     fi
  2169.     echo "mv $uconfsh $uconfsh.done" >> $DIR_TARGET/$uconfsh
  2170.     chmod 755 $DIR_TARGET/$uconfsh
  2171. }
  2172.  
  2173.  
  2174. Fix_Paper_Size()
  2175. {
  2176.     local paper="`get_val CONF_PRINTER1_PAPER`"
  2177.  
  2178.     case $paper in
  2179.     a3)
  2180.         paper="A3"
  2181.         ;;
  2182.     a4)
  2183.         paper="A4"
  2184.         ;;
  2185.     a5)
  2186.         paper="A5"
  2187.         ;;
  2188.     letter)
  2189.         paper="Letter"
  2190.         ;;
  2191.     legal)
  2192.         paper="Legal"
  2193.         ;;
  2194.     ledger)
  2195.         paper="Letter"
  2196.         ;;
  2197.     esac
  2198.     set_val CONF_PRINTER1_PAPER "$paper"
  2199. }
  2200.  
  2201.  
  2202. Do_Setup_Printer()
  2203. {
  2204.     local dir_default_ppd=$DIR_TARGET/etc/cups/ppd
  2205.     local dir_pool_ppd=$DIR_TARGET/usr/share/cups/model
  2206.     local file_printers_conf=$DIR_TARGET/etc/cups/printers.conf
  2207.     local printer_type="`get_val CONF_PRINTER1_TYPE`"
  2208.     local file_ppd="`get_val CONF_PRINTER1_PPD`"
  2209.     local file_default_ppd=
  2210.     local dev="`get_val CONF_PRINTER1_DEV`"
  2211.     local device_URI=
  2212.     local speed="`get_val CONF_PRINTER1_SPEED`"
  2213.     local host="`get_val CONF_PRINTER1_HOST`"
  2214.     local name="`get_val CONF_PRINTER1_NAME`"
  2215.     local name_default="ps1"
  2216.     local res="`get_val CONF_PRINTER1_RES`"
  2217.     local paper
  2218.  
  2219.     if [ -z "$name" ]; then
  2220.         name="$name_default"
  2221.     fi
  2222.     Fix_Paper_Size
  2223.     paper="`get_val CONF_PRINTER1_PAPER`"
  2224.     if [ -z "$paper" ]; then
  2225.         paper="Letter"
  2226.     fi
  2227.     if [ -z "$speed" ]; then
  2228.         speed="9600"
  2229.     fi
  2230.     if [ -z "$dev" ]; then
  2231.         device_URI="parallel:/dev/lp0"
  2232.     else
  2233.         case $dev in
  2234.         /dev/lp0|/dev/lp1|/dev/lp2)
  2235.             device_URI="parallel:${dev}"
  2236.             ;;
  2237.         /dev/ttyS0|/dev/ttyS1|/dev/ttyS2|/dev/ttyS3)
  2238.             device_URI="serial:${dev}"'?'"baud=$speed"
  2239.             ;;
  2240.         /dev/usb/lp0|/dev/usb/lp1|/dev/usb/lp2)
  2241.             device_URI="usb:${dev}"
  2242.             ;;
  2243.         esac
  2244.     fi
  2245.     file_default_ppd=${dir_default_ppd}/${name}.ppd
  2246.     mkdir -p $dir_default_ppd
  2247.     sed "{
  2248.         \;^\*Default.*Letter[     ]*$;s;Letter;${paper};
  2249.         }" ${dir_pool_ppd}/${file_ppd} > $file_default_ppd
  2250.     
  2251.     if [ ! -f $file_printers_conf ]; then
  2252.         Debug "$file_printers_conf: file not found"
  2253.         Debug "Skipping manipulation of it."
  2254.         return 1
  2255.     fi
  2256.     sed '{
  2257.         /^# The following/,$d
  2258.         }' $file_printers_conf > ${file_printers_conf}.tmp
  2259.     chmod 644 ${file_printers_conf}.tmp
  2260.     mv ${file_printers_conf}.tmp $file_printers_conf
  2261.     cat << EOF >> $file_printers_conf
  2262. # The following configuration is written by Caldera LISA on `date`
  2263. <DefaultPrinter ${name}>
  2264. Info ${printer_type}
  2265. Location
  2266. DeviceURI ${device_URI}
  2267. Accepting Yes
  2268. JobSheets none none
  2269. </Printer>
  2270. EOF
  2271. }
  2272.  
  2273.  
  2274. Build_CUPS_Printers()
  2275. {
  2276.     local file_printers_db=$DIR_LIVE/lizard/share/apps/lizard/printers
  2277.  
  2278.     if [ ! -f $file_printers_db ]; then
  2279.         file_printers_db=$DIR_TARGET/usr/share/hwdata/printers
  2280.     fi
  2281.     if [ ! -f $file_printers_db ]; then
  2282.         echo "$file_printers_db: file not found."
  2283.         return 1
  2284.     fi
  2285.     # Our sed is horribly old and broken, so we have to work around it
  2286.     cut -d':' -f 1,2,6,7 $file_printers_db | \
  2287.         sed '{
  2288.             /^#/d
  2289.             s/:/ /
  2290.             s/:/ /
  2291.             s/ /,/g
  2292.             }' | do_quote | \
  2293.         sed '{
  2294.             s/:/;/
  2295.             s/:.* "/"/
  2296.             s/;/:/
  2297.             s/,/ /g
  2298.             }'
  2299. }
  2300.  
  2301.  
  2302. Menu_Config_Printer_cups()
  2303. {
  2304.     local type=
  2305.     local ppd=
  2306.     local dev=
  2307.     local speed=
  2308.     local res=
  2309.     local paper=
  2310.     local print_rm=
  2311.     local print_rp=
  2312.     local pnum=
  2313.  
  2314.     Fix_Paper_Size
  2315.     while [ 1 ]; do
  2316.         Choose --none --other --build Build_CUPS_Printers PRINTER CONF_PRINTER1_TYPE || return 1
  2317.         type="`echo $ANSWER | cut -d':' -f 1`"
  2318.         ppd="`echo $ANSWER | cut -d':' -f 2`"
  2319.         if [ -z "$type" ]; then
  2320.             type=
  2321.             ppd=
  2322.             dev=
  2323.             speed=
  2324.         else
  2325.             # printer device
  2326.             Choose --other --menutitle ":CHOOSE_PRINTER_DEV_MENUTITLE:" PRINTER_DEV CONF_PRINTER1_DEV || return 1
  2327.             dev="$ANSWER"
  2328.             if [ -n "`echo $dev | fgrep /dev/ttyS `" ]; then
  2329.                 if [ "$dev" = "`Get_Val CONF_MOUSE1_DEV`" ]; then
  2330.                     Warn ":WARN_MOUSE_PRINTER_DEV_CONFLICT:" || continue
  2331.                 fi
  2332.                 if [ "$dev" = "`Get_Val CONF_MODEM1_DEV`" ]; then
  2333.                     Warn ":WARN_MODEM_PRINTER_DEV_CONFLICT:" || continue
  2334.                 fi
  2335.                 # printer serial portspeed
  2336.                 Choose SERIAL_SPEED CONF_PRINTER1_SPEED || continue
  2337.                 speed="$ANSWER"
  2338.             else
  2339.                 speed=
  2340.             fi
  2341.             # FIXME: ask Klaus about printer resolution
  2342.             # printer resolution
  2343.             #Choose PRINTER_RES CONF_PRINTER1_RES || continue
  2344.             #res="$ANSWER"
  2345.             # printer paper size
  2346.             Choose PRINTER_PAPER CONF_PRINTER1_PAPER || continue
  2347.             paper="$ANSWER"
  2348.         fi
  2349.         Do_Store CONF_PRINTER1_TYPE "$type"
  2350.         Do_Store CONF_PRINTER1_PPD "$ppd"
  2351.         Do_Store CONF_PRINTER1_DEV "$dev"
  2352.         Do_Store CONF_PRINTER1_SPEED "$speed"
  2353.         Do_Store CONF_PRINTER1_HOST "$print_rm"
  2354.         Do_Store CONF_PRINTER1_NAME "$print_rp"
  2355.         Do_Store CONF_PRINTER1_RES "$res"
  2356.         Do_Store CONF_PRINTER1_PAPER "$paper"
  2357.         Do_Setup_Printer
  2358.         return 0
  2359.     done
  2360. }
  2361.  
  2362.  
  2363. Menu_Config_Printer_lpd()
  2364. {
  2365.     local type=
  2366.     local dev=
  2367.     local speed=
  2368.     local res=
  2369.     local paper=
  2370.     local print_rm=
  2371.     local print_rp=
  2372.     local file_lpd_conf=$DIR_TARGET/etc/lpd.conf
  2373.     local print_grp_def=daemon
  2374.     local print_grp=
  2375.     local uconfsh=/etc/rc.d/unconfigured.sh
  2376.     local print_genfilter=$DIR_TARGET/usr/lib/LST/lisa/genfilter
  2377.     local print_template=$DIR_TARGET/usr/lib/LST/lisa/filter-template
  2378.     local pnum=
  2379.  
  2380.     if [ -f $file_lpd_conf ]; then
  2381.         # compiled-in value overwritten?
  2382.         print_grp="`get_val -f $file_lpd_conf group`"
  2383.         if [ -z "$print_grp" ]; then
  2384.             # compiled-in value mentionned?
  2385.             print_grp="`fgrep group= $file_lpd_conf | sed -n '1,1p' | cut -d'=' -f 2`"
  2386.         fi
  2387.     fi
  2388.     if [ -z "$print_grp" ]; then
  2389.         print_grp="$print_grp_def"
  2390.     fi
  2391.   
  2392.     while [ 1 ]; do
  2393.         # printer type
  2394.         Choose --none --other PRINTER CONF_PRINTER1_TYPE || return 1
  2395.         type="$ANSWER"
  2396.         if [ -z "$type" ]; then
  2397.             type=
  2398.             dev=
  2399.             speed=
  2400.         elif [ "$type" = "NET" ]; then
  2401.             print_rm="`Get_Val CONF_PRINTER1_HOST`"
  2402.             Ask_String PRINTER_REMOTE_HOST "$print_rm"|| return 1
  2403.             print_rm="$ANSWER"
  2404.             print_rp="`Get_Val CONF_PRINTER1_NAME`"
  2405.             if [ -z "$print_rp" -o "$MODE_QUERY" != "auto" ]; then
  2406.                 print_rp="ps"
  2407.             fi
  2408.             Ask_String PRINTER_REMOTE_DEV "$print_rp" || return 1
  2409.             print_rp="$ANSWER"
  2410.             type="NET"
  2411.         else
  2412.             # printer device
  2413.             Choose --other --menutitle ":CHOOSE_PRINTER_DEV_MENUTITLE:" PRINTER_DEV CONF_PRINTER1_DEV || return 1
  2414.             dev="$ANSWER"
  2415.             if [ -n "`echo $dev | fgrep /dev/ttyS `" ]; then
  2416.                 if [ "$dev" = "`Get_Val CONF_MOUSE1_DEV`" ]; then
  2417.                     Warn ":WARN_MOUSE_PRINTER_DEV_CONFLICT:" || continue
  2418.                 fi
  2419.                 if [ "$dev" = "`Get_Val CONF_MODEM1_DEV`" ]; then
  2420.                     Warn ":WARN_MODEM_PRINTER_DEV_CONFLICT:" || continue
  2421.                 fi
  2422.                 # printer serial portspeed
  2423.                 Choose SERIAL_SPEED CONF_PRINTER1_SPEED || continue
  2424.                 speed="$ANSWER"
  2425.             else
  2426.                 speed=
  2427.             fi
  2428.             # printer resolution
  2429.             Choose PRINTER_RES CONF_PRINTER1_RES || continue
  2430.             res="$ANSWER"
  2431.             # printer paper size
  2432.             Choose PRINTER_PAPER CONF_PRINTER1_PAPER || continue
  2433.             paper="$ANSWER"
  2434.         fi
  2435.         Do_Store CONF_PRINTER1_TYPE "$type"
  2436.         Do_Store CONF_PRINTER1_DEV "$dev"
  2437.         Do_Store CONF_PRINTER1_SPEED "$speed"
  2438.         Do_Store CONF_PRINTER1_HOST "$print_rm"
  2439.         Do_Store CONF_PRINTER1_NAME "$print_rp"
  2440.         Do_Store CONF_PRINTER1_RES "$res"
  2441.         Do_Store CONF_PRINTER1_PAPER "$paper"
  2442.  
  2443.         if [ -n "$type" ]; then
  2444.             # we have configured a printer
  2445.             # FIXME: Uaaahhh!
  2446.             # if printcap exists we disable everything with '#'
  2447.             if [ -f $DIR_TARGET/etc/printcap ]; then
  2448.                 cp -a $DIR_TARGET/etc/printcap $DIR_TARGET/etc/printcap.lisasave
  2449.                 sed '/^[^#]/s/^/#/' $DIR_TARGET/etc/printcap.lisasave \
  2450.                     > $DIR_TARGET/etc/printcap
  2451.             fi
  2452.             if [ "$type" = "NET" ]; then
  2453.                 # it is a network printer
  2454.                 # add network entry to /etc/printcap
  2455.                 cat << EOF >> $DIR_TARGET/etc/printcap
  2456. ##PRINTTOOL## REMOTE 
  2457. lp|ps:\\
  2458.         :sd=/var/spool/lpd/lp:\\
  2459.         :mx#0:\\
  2460.         :rm=$print_rm:\\
  2461.         :rp=$print_rp:
  2462. EOF
  2463.             else
  2464.                 # it is a local printer
  2465.                 if [ -n "$dev" ]; then
  2466.                     # make sure printer dev has the right settings
  2467.                     chown root.${print_grp} $DIR_TARGET/${dev}
  2468.                     chmod 660 $DIR_TARGET/${dev}
  2469.                 fi
  2470.                 # add local entry to /etc/printcap
  2471.                 cat << EOF >> $DIR_TARGET/etc/printcap
  2472. ##PRINTTOOL## LOCAL $type $res $paper {}
  2473. ps:\\
  2474.         :sd=/var/spool/lpd/ps:\\
  2475.         :mx#0:\\
  2476.         :lp=$dev:\\
  2477.         :if=/var/spool/lpd/ps/filter:\\
  2478.         :sh:
  2479. ##PRINTTOOL## LOCAL
  2480. lp:\\
  2481.     :sd=/var/spool/lpd/lp:\\
  2482.     :mx#0:\\
  2483.     :lp=$dev:\\
  2484.     :sh:
  2485. EOF
  2486.                 mkdir -p $DIR_TARGET/var/spool/lpd/ps
  2487.                 if [ ! -f $print_genfilter ]; then
  2488.                     print_genfilter=$DIR_TARGET/usr/lib/rhs/control-panel/genfilter
  2489.                     print_template=$DIR_TARGET/usr/lib/rhs/control-panel/filter-template
  2490.                 fi
  2491.                 $print_genfilter $type $res $paper \
  2492.                     < $print_template \
  2493.                     > $DIR_TARGET/var/spool/lpd/ps/filter
  2494.                 chmod 755 $DIR_TARGET/var/spool/lpd/ps/filter
  2495.             fi
  2496.  
  2497.             # FIXME: create lp devices that match in owner.group what LPRng expects
  2498.             for pnum in 0 1 2 ; do
  2499.                 rm -f $DIR_TARGET/dev/lp${pnum}
  2500.                 mknod -m 660 $DIR_TARGET/dev/lp${pnum} c 6 ${pnum}
  2501.                 chown root.${print_grp} $DIR_TARGET/dev/lp${pnum}
  2502.             done
  2503.  
  2504.             # check permissions
  2505.             if [ "$DIR_TARGET" != "/" ]; then
  2506.                 echo 'if [ -x /usr/sbin/checkpc ]; then ' >> $DIR_TARGET/$uconfsh
  2507.                 echo "echo -n \" checkpc\" " >> $DIR_TARGET/$uconfsh
  2508.                 echo '/usr/sbin/checkpc -f > /tmp/checkpc.log 2>&1 ' >> $DIR_TARGET/$uconfsh
  2509.                 # simple FIX (once only) for broken checkpc in LST 2.2
  2510.                 echo '  if [ -f /var/spool/lpd/ps/filter ]; then' >> $DIR_TARGET/$uconfsh
  2511.                 echo '    chmod +x /var/spool/lpd/ps/filter' >> $DIR_TARGET/$uconfsh
  2512.                 echo '  fi' >> $DIR_TARGET/$uconfsh
  2513.                 echo 'fi' >> $DIR_TARGET/$uconfsh
  2514.             else
  2515.                 if [ -x /usr/sbin/checkpc ]; then
  2516.                     /usr/sbin/checkpc -f > /tmp/checkpc.log 2>&1
  2517.                     /etc/rc.d/init.d/lpd restart > /dev/null 2>&1
  2518.                 fi
  2519.             fi
  2520.         fi
  2521.         return 0
  2522.     done
  2523. }
  2524.  
  2525. Choose_Lang()
  2526. {
  2527.   local i
  2528.   local lang_list_supported="us de fr it es"
  2529.   local lang_list_available=""
  2530.   local my_lang="`get_val CONF_LST_LANG`"
  2531.   local fixed_title="Language Selection"
  2532.   local fixed_message="The following languages are currently available. Use the arrow keys to select."
  2533.  
  2534.   for i in $lang_list_supported ; do
  2535.     if [ -f /usr/lib/LST/$i/libLSTtext ]; then
  2536.       lang_list_available="$lang_list_available $i"
  2537.     fi
  2538.   done
  2539.  
  2540.   if [ -z "$lang_list_available" ]; then
  2541.     Error "No language choice available."
  2542.     return 1
  2543.   fi
  2544.  
  2545.   cat << EOF > /tmp/LST/command
  2546. #!/bin/sh
  2547. $CMD_BOX --title "$fixed_title" \\
  2548.     --default "$my_lang" \\
  2549.     --one "$fixed_message" \\
  2550. EOF
  2551.   for i in $lang_list_available ; do
  2552.     case $i in
  2553.     us)
  2554.       echo "\"us\"    \"English\" \\" >> /tmp/LST/command
  2555.       ;;
  2556.     de)
  2557.       echo "\"de\"    \"Deutsch\" \\" >> /tmp/LST/command
  2558.       ;;
  2559.     fr)
  2560.       echo "\"fr\"    \"FranÏ„ais\" \\" >> /tmp/LST/command
  2561.       ;;
  2562.     it)
  2563.       echo "\"it\"    \"Italiano\" \\" >> /tmp/LST/command
  2564.       ;;
  2565.     es)
  2566.       echo "\"es\"    \"Espa±ol\" \\" >> /tmp/LST/command
  2567.       ;;
  2568.     esac
  2569.   done
  2570.   echo "2> /tmp/LST/answer" >> /tmp/LST/command
  2571.   chmod 755 /tmp/LST/command
  2572.   sh /tmp/LST/command
  2573.  
  2574.   if [ -s /tmp/LST/answer ]; then
  2575.     my_lang="`cat /tmp/LST/answer`"
  2576.   fi
  2577.  
  2578.   set_val CONF_LST_LANG "$my_lang"
  2579.   return 0
  2580. }
  2581.  
  2582. Menu_Config_Term()
  2583. {
  2584.   while [ 1 ]; do
  2585.     Choose TERM || return 1
  2586.     export TERM="$ANSWER"
  2587.     Ask_String TERM_TEST && break
  2588.   done
  2589.   Do_Store TERM "$TERM"
  2590.   return 0
  2591. }
  2592.  
  2593. Menu_Config_Printer()
  2594. {
  2595.     if [ -x $DIR_TARGET/usr/sbin/cupsd ]; then
  2596.         Menu_Config_Printer_cups || return 1
  2597.         return 0
  2598.     else
  2599.         Menu_Config_Printer_lpd || return 1
  2600.         return 0
  2601.     fi
  2602. }
  2603.  
  2604.  
  2605. Menu_Config_Timezone()
  2606. {
  2607.     local tz_flag="`Get_Val CONF_KERNTZ_FLAG`"
  2608.     local tz_zone="`Get_Val CONF_TIMEZONE`"
  2609.  
  2610.     Choose KERNTZ $tz_flag || return 1
  2611.     Debug "KERNTZ=<$ANSWER>" 
  2612.     if [ "$ANSWER" = "KTZ_UTCTIME" ]; then
  2613.         Do_Store CONF_KERNTZ_FLAG "u"
  2614.     else
  2615.         Do_Store CONF_KERNTZ_FLAG ""
  2616.     fi
  2617.     Choose TIMEZONE $tz_zone || return 1
  2618.     Do_Store CONF_TIMEZONE "$ANSWER"
  2619.     Set_clock
  2620.     return 0
  2621. }
  2622.  
  2623. Get_Symlink()
  2624. {
  2625.   ls -l $1 | sed 's/^.* -> \(.*\)/\1/p'
  2626. }
  2627.  
  2628. Get_X_Server()
  2629. {
  2630.   if [ -f $DIR_TARGET/usr/X11R6/bin/X ]; then
  2631.     basename `Get_Symlink $DIR_TARGET/usr/X11R6/bin/X`
  2632.   fi
  2633. }
  2634.  
  2635. Do_Setup_X()
  2636. {
  2637.   local uconfsh=/etc/rc.d/unconfigured.sh
  2638.   local server="unknown"
  2639.   local label
  2640.   local tool
  2641.  
  2642.   if [ $# -gt 0 ]; then
  2643.     server="$1"
  2644.   else
  2645.     server="`Get_X_Server`"
  2646.   fi
  2647.  
  2648.   case $server in
  2649.   XFree86)
  2650.     label=KXCONFIG
  2651.     tool=kxconfig
  2652.     ;;
  2653.   Xaccel)
  2654.     label=XSETUP
  2655.     tool=Xsetup
  2656.     ;;
  2657.   Xmetro)
  2658.     label=CONFIGX
  2659.     tool=configX
  2660.     ;;
  2661.   *)
  2662.     if [ -x $DIR_TARGET/usr/X11R6/bin/XF86Setup ]; then
  2663.       label=XF86SETUP
  2664.       tool=XF86Setup
  2665.     elif [ -x $DIR_TARGET/usr/X11R6/bin/xf86config ]; then
  2666.       label=XF86CONFIG
  2667.       tool=xf86config
  2668.     fi
  2669.     ;;
  2670.   esac
  2671.  
  2672.   Msg2 NEED_CALL_${label} || return 1
  2673.   return 0
  2674. }
  2675.  
  2676.  
  2677. Menu_Config_X_Server()
  2678. {
  2679.   local x_server=
  2680.  
  2681.   x_server=
  2682.   while [ 1 ]; do
  2683.     List X_SERVER | sed 's/ :.*$//' > $FILE_TMP_ANSWER
  2684.     if [ ! -s $FILE_TMP_ANSWER ]; then
  2685.       Error2 X_SERVER_NOT_INSTALLED
  2686.       Debug "NO X_Server found !?"
  2687.       return 1
  2688.     fi
  2689.     if [ -n "`sed '1d' $FILE_TMP_ANSWER`" ]; then
  2690.       Choose X_SERVER $x_server || return 1
  2691.       x_server="$ANSWER"
  2692.     else
  2693.       x_server="`cat $FILE_TMP_ANSWER`"
  2694.       Debug "taking '$x_server' from List X_SERVER"
  2695.     fi
  2696.     if [ -f /usr/X11R6/bin/$x_server ]; then
  2697.       break
  2698.     fi
  2699.     if [ -f $DIR_TARGET/usr/X11R6/bin/$x_server ]; then
  2700.       break
  2701.     fi
  2702.     Error2 X_SERVER_NOT_INSTALLED
  2703.   done
  2704.   Do_Store CONF_X_SERVER1_TYPE "$x_server"
  2705.   ( cd $DIR_TARGET/usr/X11R6/bin ; rm -f X ; ln -sf $x_server X )
  2706.   Do_Setup_X $x_server
  2707.   return 0
  2708. }
  2709.  
  2710. Menu_Analyse()
  2711. {
  2712.   while [ 1 ]; do
  2713.     $CMD_BOX --help ":MENU_ANALYSE_HELP:" \
  2714. --title ":MENU_ANALYSE_TITLE:" \
  2715. --menu ":MENU_ANALYSE_TEXT:" \
  2716. "Show_System_Info" ":MENU_ANALYSE_SYSTEM:" \
  2717. "Show_Kernel_Info" ":MENU_ANALYSE_KERNEL:" \
  2718. "Show_Hardware_Info" ":MENU_ANALYSE_HARDWARE:" \
  2719. "Show_Partition_Info" ":MENU_ANALYSE_PARTITION:" \
  2720. "Menu_Analyse_Net" ":MENU_ANALYSE_NET:" \
  2721. "Show_Boot_Msg" ":SHOW_BOOT_MSG:" \
  2722. "Show_LST_Config" ":SHOW_LST_CONFIG:" \
  2723. "Show_System_Config" ":SHOW_SYSTEM_CONFIG:" 2> $FILE_TMP_ANSWER
  2724.     if [ $? -ne 0 ]; then
  2725.       return 1
  2726.     fi
  2727.     COMMAND="`cat $FILE_TMP_ANSWER`"
  2728.     $COMMAND
  2729.   done
  2730. }
  2731.  
  2732. Menu_Config_Hardware()
  2733. {
  2734.   local item=
  2735.   while [ 1 ]; do
  2736.     if [ -z "$item" ]; then item="Menu_Config_Floppy" ; fi
  2737.     $CMD_BOX --help ":MENU_CONFIG_HARDWARE_HELP:" \
  2738. --default "$item" \
  2739. --title ":MENU_CONFIG_HARDWARE_TITLE:" \
  2740. --menu ":MENU_CONFIG_HARDWARE_TEXT:" \
  2741. "Menu_Config_Floppy" ":MENU_CONFIG_FLOPPY:" \
  2742. "Menu_Config_Harddisk" ":MENU_CONFIG_HARDDISK:" \
  2743. "Menu_Config_Keyboard" ":MENU_CONFIG_KEYBOARD:" \
  2744. "Menu_Config_Modem" ":MENU_CONFIG_MODEM:" \
  2745. "Menu_Config_Mouse" ":MENU_CONFIG_MOUSE:" \
  2746. "Menu_Config_Printer" ":MENU_CONFIG_PRINTER:" \
  2747. "Menu_Config_CD" ":MENU_CONFIG_CD:" \
  2748. "Menu_Config_Tape" ":MENU_CONFIG_TAPE:" \
  2749. "Menu_Config_X_Server" ":CHOOSE_X_SERVER:" 2> $FILE_TMP_ANSWER || break
  2750.     COMMAND="`cat $FILE_TMP_ANSWER`"
  2751.     item="$COMMAND"
  2752.     if [ -n "$COMMAND" ]; then
  2753.       $COMMAND
  2754.     fi
  2755.   done
  2756.   return 0
  2757. }
  2758.  
  2759. Menu_Config_System()
  2760. {
  2761.   local item=
  2762.  
  2763.   while [ 1 ]; do
  2764.     if [ -z "$item" ]; then item="Menu_Config_User" ; fi
  2765.     $CMD_BOX --help ":MENU_CONFIG_SYSTEM_HELP:" \
  2766. --default "$item" \
  2767. --title ":MENU_CONFIG_SYSTEM_TITLE:" \
  2768. --menu ":MENU_CONFIG_SYSTEM_TEXT:" \
  2769. "Menu_Config_User" ":MENU_CONFIG_USER:" \
  2770. "Menu_Config_Mount" ":MENU_CONFIG_MOUNT:" \
  2771. "Menu_Config_Swap" ":MENU_CONFIG_SWAP:" \
  2772. "Menu_Config_FQ_Name" ":MENU_CONFIG_HOSTNAME:" \
  2773. "Menu_Config_Timezone" ":CHOOSE_TIMEZONE:" \
  2774. "Menu_Config_Daemons" ":MENU_CONFIG_DAEMONS:" \
  2775. "Menu_Config_Kernel" ":MENU_CONFIG_KERNEL:" 2> $FILE_TMP_ANSWER || break
  2776.     COMMAND="`cat $FILE_TMP_ANSWER`"
  2777.     item="$COMMAND"
  2778.     if [ -n "$COMMAND" ]; then
  2779.       $COMMAND
  2780.     fi
  2781.   done
  2782.   return 0
  2783. }
  2784.  
  2785. Menu_Config()
  2786. {
  2787.   local item=
  2788.   while [ 1 ]; do
  2789.     if [ -z "$item" ]; then item="Menu_Config_System" ; fi
  2790.     $CMD_BOX --help ":MENU_CONFIG_HELP:" \
  2791. --default "$item" \
  2792. --title ":MENU_CONFIG_TITLE:" \
  2793. --menu ":MENU_CONFIG_TEXT:" \
  2794. "Menu_Config_Hardware" ":MENU_CONFIG_HARDWARE:" \
  2795. "Menu_Config_System" ":MENU_CONFIG_SYSTEM:" \
  2796. "Menu_Config_Net" ":MENU_CONFIG_NET:" \
  2797. "Menu_Config_LILO_HD" ":MENU_CONFIG_BOOT:" 2> $FILE_TMP_ANSWER || break
  2798.     COMMAND="`cat $FILE_TMP_ANSWER`"
  2799.     item="$COMMAND"
  2800.     if [ -n "$COMMAND" ]; then
  2801.       $COMMAND
  2802.     fi
  2803.   done
  2804.   return 0
  2805. }
  2806.  
  2807. Menu_Main()
  2808. {
  2809.   local item=
  2810.  
  2811.  
  2812.   History "`date` $LOGNAME: LISA: calling main"
  2813.   while [ 1 ]; do
  2814.     if [ -z "$item" ]; then item="Menu_Config" ; fi
  2815.     $CMD_BOX --help ":MENU_MAIN_HELP:" \
  2816. --default "$item" \
  2817. --title ":MENU_MAIN_TITLE:" \
  2818. --menu ":MENU_MAIN_TEXT:" \
  2819. "Menu_Analyse" ":MENU_ANALYSE:" \
  2820. "Menu_Pkg" ":MENU_PKG:" \
  2821. "Menu_Config" ":MENU_CONFIG:" \
  2822. "hilfe" ":MENU_HELP:" 2> $FILE_TMP_ANSWER || break
  2823.     COMMAND="`cat $FILE_TMP_ANSWER`"
  2824.     item="$COMMAND"
  2825.     if [ -n "$COMMAND" ]; then
  2826.       $COMMAND
  2827.     fi
  2828.   done
  2829.   return 0
  2830. }
  2831.  
  2832. Menu_Setup()
  2833. {
  2834.   History "`date` $LOGNAME: LISA: calling setup"
  2835.   Choose_Lang
  2836.   # Menu_Config_Term
  2837. }
  2838.  
  2839. Do_Setup_locate()
  2840. {
  2841.   local uconfsh=/etc/rc.d/unconfigured.sh
  2842.  
  2843.   echo 'if [ -x /usr/bin/updatedb ]; then ' >> $DIR_TARGET/$uconfsh
  2844.   echo "echo -n \" locate\" " >> $DIR_TARGET/$uconfsh
  2845.   echo '/usr/bin/updatedb --prunepaths="/tmp /proc /mnt /var/tmp /var/spool /dev /net /auto /amd" --netuser=nobody > /dev/null 2>&1 &' >> $DIR_TARGET/$uconfsh
  2846.   echo 'fi' >> $DIR_TARGET/$uconfsh
  2847. }
  2848.  
  2849. Do_Setup_teTeX()
  2850. {
  2851.   local uconfsh=/etc/rc.d/unconfigured.sh
  2852.  
  2853.   echo 'if [ -x /usr/TeX/bin/texconfig ]; then ' >> $DIR_TARGET/$uconfsh
  2854.   echo "echo -n \" teTeX\" " >> $DIR_TARGET/$uconfsh
  2855.   echo '( cd /usr/TeX/bin ; texhash > /dev/null 2>&1 )' >> $DIR_TARGET/$uconfsh
  2856.   echo '( cd /usr/TeX/bin ; texconfig init > /dev/null 2>&1 )' >> $DIR_TARGET/$uconfsh
  2857.   echo 'fi' >> $DIR_TARGET/$uconfsh
  2858. }
  2859.  
  2860.  
  2861. # libLSTboot - boot config library shared between several scripts
  2862. #
  2863. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  2864. #
  2865.  
  2866. Do_Create_Generic_LILO_Message()
  2867. {
  2868.     rm -f $FILE_LILO_MESSAGE
  2869.     touch $FILE_LILO_MESSAGE || return 1
  2870.     chmod 400 $FILE_LILO_MESSAGE || return 1
  2871.     cat << EOF >> $FILE_LILO_MESSAGE
  2872.  
  2873.             LILO Bootloader
  2874.  
  2875.       (LST Linux generic message)
  2876.  
  2877. Press <TAB> to see possible boot choices.
  2878.  
  2879. Then enter the desired choice or press <Return>"
  2880. to boot the default (first) choice."
  2881.  
  2882. EOF
  2883.     return 0
  2884. }
  2885.  
  2886. Do_Create_Generic_LILO_Conf()
  2887. {
  2888.     local target="$1"
  2889.  
  2890.     rm -f $DIR_TARGET/$FILE_LILO_CONF.tmp
  2891.     cat << EOF > $DIR_TARGET/$FILE_LILO_CONF.tmp
  2892. #
  2893. # general section
  2894. #
  2895. EOF
  2896.     if Is_SPARC ; then
  2897.         cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  2898. root = $target
  2899. partition = 1
  2900. EOF
  2901.     else
  2902.         cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  2903. boot = $target
  2904. install = /boot/boot.b
  2905. EOF
  2906.     fi
  2907.     cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  2908. message = $FILE_LILO_MESSAGE
  2909. prompt
  2910.  
  2911. # wait 20 seconds (200 10ths) for user to select the entry to load
  2912. timeout = 200
  2913.  
  2914. #
  2915. # default entry
  2916. #
  2917.  
  2918. EOF
  2919.     chmod 600 $DIR_TARGET/$FILE_LILO_CONF.tmp
  2920.     return 0
  2921. }
  2922.  
  2923. Check_LILO()
  2924. {
  2925.     rm -f /tmp/mbr
  2926.     if [ $# -gt 0 ]; then
  2927.         dd if=$1 bs=1 skip=2 count=4 of=/tmp/mbr 2> /dev/null
  2928.     else
  2929.         dd if=/dev/hda bs=1 skip=2 count=4 of=/tmp/mbr 2> /dev/null
  2930.         if [ ! -s /tmp/mbr ]; then
  2931.             dd if=/dev/sda bs=1 skip=2 count=4 of=/tmp/mbr 2> /dev/null
  2932.         fi
  2933.     fi
  2934.  
  2935.     if [ ! -s /tmp/mbr ]; then
  2936.         rm -f /tmp/mbr
  2937.         return 1
  2938.     else
  2939.         fgrep LILO /tmp/mbr > /dev/null
  2940.         if [ $? -eq 0 ]; then
  2941.             ANSWER="LILO"
  2942.         else
  2943.             ANSWER="unknown"
  2944.         fi
  2945.     fi
  2946.     rm -f /tmp/mbr
  2947.     return 0
  2948. }
  2949.  
  2950. Build_KERNEL_IMAGE()
  2951. {
  2952.     List_KERNEL_IMAGE $1 | do_quote
  2953. }
  2954.  
  2955. Build_LILO_ENTRY()
  2956. {
  2957.     Build_KERNEL_IMAGE $1
  2958.     Build_Other_OS
  2959. }
  2960.  
  2961. List_KERNEL_IMAGE()
  2962. {
  2963.   local prefix="$1"
  2964.   local prefixed_image
  2965.   local image
  2966.  
  2967.   for prefixed_image in $prefix/vmlinuz* $prefix/boot/vmlinuz* ; do
  2968.     if [ -f $prefixed_image ]; then
  2969.       image="`echo $prefixed_image | sed "s:^$prefix::"`"
  2970.       echo "$image (Linux Kernel Image)"
  2971.     fi
  2972.   done
  2973. }
  2974.  
  2975. Build_Other_OS()
  2976. {
  2977.     local i=
  2978.  
  2979.     # check for Linux partitions with LILO
  2980.     for i in `sysinfo --tag -C Linux --partition` ; do
  2981.         Check_LILO $i
  2982.         if [ $? -eq 0 -a "$ANSWER" = "LILO" ]; then
  2983.             sysinfo --postlabel " (LILO)" --box -P $i --partition
  2984.         fi
  2985.     done
  2986.     sysinfo --postlabel " (DOS or OS/2)" --box -C DOSC --partition
  2987.     sysinfo --postlabel " (OS/2)" --box -C Bootmanager --partition
  2988.     sysinfo --postlabel " (BSD)" --box -C BSD --partition
  2989.     sysinfo --postlabel " (Solaris?)" --box -C Solaris --partition
  2990. }
  2991.  
  2992. Build_LILO_ADD_ENTRY()
  2993. {
  2994.     cat << EOF
  2995. "END" ":TYPE_LILO_ADD_ENTRY_NONE:" \\
  2996. EOF
  2997.     Build_KERNEL_IMAGE $1
  2998.     Build_Other_OS
  2999. }
  3000.  
  3001. Build_LILO_MODE()
  3002. {
  3003.     local boot_mode=
  3004.  
  3005.     Is_Expert
  3006.     if [ $? -eq 0 ]; then
  3007.         # echo "\"FLOPPY\" \":TYPE_LILO_MODE_FLOPPY:\" \\"
  3008.         echo "\"LILOACTIVE\" \":TYPE_LILO_MODE_ACTIVE:\" \\"
  3009.         echo "\"LILOPASSIVE\" \":TYPE_LILO_MODE_PASSIVE:\" \\"
  3010.     else
  3011.         echo "\"LILOACTIVE\" \":TYPE_LILO_MODE_ACTIVE:\" \\"
  3012.         echo "\"ROOT\" \":TYPE_LILO_MODE_PASSIVE:\" \\"
  3013.     fi
  3014.     echo "\"MBR\" \":TYPE_LILO_MODE_MBR:\" \\"
  3015.     echo "\"NONE\" \":TYPE_LILO_MODE_NONE:\" \\"
  3016. }
  3017.  
  3018. Build_LILO_TARGET()
  3019. {
  3020.     local root_part="$1"
  3021.     local protect_root=
  3022.  
  3023.     if [ $# -gt 1 -a "$2" = "msdos" ]; then
  3024.         protect_root=true
  3025.     fi
  3026.  
  3027.     if [ -n "`sysinfo --tag --disk | fgrep -x /dev/hda`" ]; then
  3028.         echo "\"/dev/hda\" \":TYPE_LILO_TARGET_MBR_IDE:\" \\"
  3029.     fi
  3030.     if [ -n "`sysinfo --tag --disk | fgrep -x /dev/sda`" ]; then
  3031.         echo "\"/dev/sda\" \":TYPE_LILO_TARGET_MBR_SCSI:\" \\"
  3032.     fi
  3033.     if [ -n "`sysinfo --tag --disk | fgrep -x /dev/rd/c0d0`" ]; then
  3034.         echo "\"/dev/rd/c0d0\" \":TYPE_LILO_TARGET_MBR_SCSI: (/dev/rd/c0d0)\" \\"
  3035.     fi
  3036.     if [ -n "`sysinfo --tag --disk | fgrep -x /dev/ida/c0d0`" ]; then
  3037.         echo "\"/dev/ida/c0d0\" \":TYPE_LILO_TARGET_MBR_SCSI: (/dev/ida/c0d0)\" \\"
  3038.     fi
  3039.     if [ -z "$protect_root" ]; then
  3040.         echo "\"$root_part\" \":TYPE_LILO_TARGET_ROOT: ($root_part)\" \\"
  3041.     fi
  3042.     if [ -n "`sysinfo --expert --tag -C LILOPASSIVE --partition | fgrep -v $root_part`" ]; then
  3043.         echo "\"OTHER\" \":TYPE_LILO_TARGET_OTHER:\" \\"
  3044.     fi
  3045.         echo "\"/dev/fd0\" \":TYPE_LILO_TARGET_FLOPPY:\" \\"
  3046.     echo "\"NONE\" \":TYPE_LILO_TARGET_NONE:\" \\"
  3047.  
  3048.     return 0
  3049. }
  3050.  
  3051. Build_LILO_TARGET_OTHER()
  3052. {
  3053.     local root_part="$1"
  3054.  
  3055.     sysinfo --box --partition -C LILOPASSIVE | fgrep -v "\"$root_part\""
  3056.     # expert users may like to install LILO in extended partitions
  3057.     sysinfo --box --partition -C extended
  3058. }
  3059.  
  3060. Do_Analyse_Boot_Setup()
  3061. {
  3062.     local mbr=
  3063.     local dummy=
  3064.     local bios_boot=
  3065.     local active_partitions=
  3066.     local os2_bootmgr=
  3067.     local lilo_in_mbr=
  3068.  
  3069.     echo "======================================================================"
  3070.     echo "                         LISA boot analysis"
  3071.     echo "======================================================================"
  3072.     echo
  3073.  
  3074.     # check if there is a LILO in the MBR
  3075.     echo "Analysis of Master Boot Record (MBR)"
  3076.     echo "------------------------------------"
  3077.     mbr="`sysinfo --tag -C MBR --disk`"
  3078.     Check_LILO $mbr
  3079.     if [ $? -eq 0 -a "$ANSWER" = "LILO" ]; then
  3080.         lilo_in_mbr=true
  3081.         cat << EOF
  3082. MBR already contains a LILO Boot Manager
  3083. This LILO can be replaced now by another LILO, left alone, or (for DOS
  3084. systems) replaced by DOS's default MBR by using the DOS 'FDISK /MBR'
  3085. command
  3086. EOF
  3087.     else
  3088.         echo "No LILO found in the MBR."
  3089.     fi
  3090.     echo
  3091.  
  3092.     # first look for active partitions
  3093.     active_partitions="`sysinfo --tag -C active --partition`"
  3094.     echo "Active partition analysis"
  3095.     echo "-------------------------"
  3096.     if [ -z "$active_partitions" ]; then
  3097.         echo "No active partitions found!"
  3098.     else
  3099.         sysinfo --label -C active --partition
  3100.     fi
  3101.  
  3102.     echo
  3103.     echo "Conclusion"
  3104.     echo "----------"
  3105.  
  3106.     if [ -n "$lilo_in_mbr" ]; then
  3107.         echo "===> The BIOS will boot from the master boot record $mbr."
  3108.         echo
  3109.         return 0
  3110.     fi
  3111.     # the BIOS will boot from the first active partition
  3112.     bios_boot="`sysinfo --tag -C active --partition | sed -n '1p'`"
  3113.     if [ -z "$bios_boot" ]; then
  3114.         echo "===> it seems you have no valid boot setup!"
  3115.         echo "===> you have 2 choices to fix that:"
  3116.         echo "A.) install a boot loader/manager in the master boot record"
  3117.         echo "    of your first hard disk."
  3118.         echo "B.) install a boot loader/manager in a primary partition on"
  3119.         echo "    the first hard disk and activate this partition."
  3120.         echo
  3121.         return 1
  3122.     fi
  3123.     echo "===> The BIOS will boot the first active partition $bios_boot."
  3124.     Check_LILO $bios_boot
  3125.     if [ $? -eq 0 -a "$ANSWER" = "LILO" ]; then
  3126.         echo "===> $bios_boot seems to contain a LILO boot manager."
  3127.     else
  3128.         # check for DOSC
  3129.         if [ "$bios_boot" = "`sysinfo --tag -C DOSC --partition`" ]; then
  3130.             echo "===> $bios_boot seems to contain a DOS boot loader."
  3131.         # check for OS/2 Bootmanager
  3132.         elif [ "$bios_boot" = "`sysinfo --tag -C Bootmanager --partition | fgrep -x $bios_boot`" ]; then
  3133.             echo "===> $bios_boot seems to contain a OS/2 boot manager."
  3134.         # check for BSD Bootmanager
  3135.         elif [ "$bios_boot" = "`sysinfo --tag -C BSD --partition | fgrep -x $bios_boot`" ]; then
  3136.             echo "===> $bios_boot seems to contain a BSD boot manager."
  3137.         # check for Solaris Bootmanager
  3138.         elif [ "$bios_boot" = "`sysinfo --tag -C Solaris --partition | fgrep -x $bios_boot`" ]; then
  3139.             echo "===> $bios_boot seems to contain a Solaris boot manager."
  3140.         else
  3141.             echo "===> $bios_boot seems to contain no (or an unknown) boot manager."
  3142.         fi
  3143.     fi
  3144.     echo
  3145.     return 0
  3146. }
  3147.  
  3148. Do_Activate_Partition()
  3149. {
  3150.     local dummy=
  3151.     local hd_dev=
  3152.     local hd_part=
  3153.     local f_name=Do_Activate_Partition
  3154.     local f_args=1 # (partition) ->
  3155.  
  3156.     Check_Args $f_name $f_args $# "$@" || return 255
  3157.  
  3158.     hd_dev=`echo "$1" | cut -c 1-8`
  3159.     if [ "$hd_dev" = "/dev/rd/" ]; then
  3160.         hd_dev=`echo "$1" | cut -c 1-12`
  3161.         hd_part=`echo "$1" | cut -c 14-`
  3162.     elif [ "$hd_dev" = "/dev/ida" ]; then
  3163.         hd_dev=`echo "$1" | cut -c 1-13`
  3164.         hd_part=`echo "$1" | cut -c 15-`
  3165.     else
  3166.         hd_part=`echo "$1" | cut -c 9-`
  3167.     fi
  3168.     dummy="$hd_dev $hd_part"
  3169.     #Info ":INFO_ACTIVATING_PARTITION:"
  3170.     activate $dummy 2> $FILE_TMP_ERR
  3171.     if [ $? -eq 0 ]; then
  3172.         Msg ":INFO_ACTIVATE_SUCCESS:"
  3173.     else
  3174.         Error --file $FILE_TMP_ERR "$1 ; :ERR_ACTIVATE_PROBLEMS:"
  3175.         return 1
  3176.     fi
  3177.     return 0
  3178. }
  3179.  
  3180. Do_Install_LILO()
  3181. {
  3182.     local lilo_cmd
  3183.  
  3184.     if Is_SPARC ; then
  3185.         lilo_cmd=silo
  3186.     else
  3187.         lilo_cmd=lilo
  3188.     fi
  3189.  
  3190.     Info ":INFO_LILO_RUNNING:"
  3191.     if [ "$DIR_TARGET" != "/" ]; then
  3192.         ( cd $DIR_TARGET; chroot $DIR_TARGET sbin/$lilo_cmd && echo "LILO ok" ) > $DIR_TARGET/tmp/lilo.error 2>&1
  3193.         mv $DIR_TARGET/tmp/lilo.error $FILE_TMP_ERR
  3194.         # $lilo_cmd -r $DIR_TARGET > $FILE_TMP_ERR 2>&1
  3195.     else
  3196.         ( /sbin/$lilo_cmd && echo "LILO ok" ) > $FILE_TMP_ERR 2>&1
  3197.     fi
  3198.     if [ -z "`fgrep -x 'LILO ok' $FILE_TMP_ERR`" ]; then
  3199.         Error --file $FILE_TMP_ERR ":ERR_LILO_PROBLEMS:"
  3200.         return 1
  3201.     else
  3202.         $CMD_BOX --nobutton --msg ":INFO_LILO_SUCCESS:"
  3203.     fi
  3204.     return 0
  3205. }
  3206.  
  3207. Do_Add_LILO_Table()
  3208. {
  3209.   local table=
  3210.   local partnum=
  3211.  
  3212.   table="`echo $1 | cut -c 1-8`"
  3213.   if [ -n "$table" ]; then
  3214.     partnum="`echo $1 | cut -c 9-`"
  3215.     if [ $partnum -lt 5 ]; then
  3216.       echo "    table = $table" >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  3217.     fi
  3218.     if ! Is_SPARC ; then
  3219.       echo "    loader = /boot/chain.b" >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  3220.     fi
  3221.   fi
  3222. }
  3223.  
  3224. Ask_LILO_Label()
  3225. {
  3226.     local label=
  3227.     local partid=
  3228.  
  3229.     echo "$1" | fgrep '/dev/' > /dev/null
  3230.     if [ $? -eq 0 ]; then
  3231.         label="`echo $1 | cut -c 6-`"
  3232.         partid="`Get_Partition_Info --id $1`"
  3233.         case $partid in
  3234.         1|4|6|11|12|14)
  3235.             label="dos"
  3236.             ;;
  3237.         10)
  3238.             label="os2"
  3239.             ;;
  3240.         130)
  3241.             label="solaris"
  3242.             ;;
  3243.         131)
  3244.             label="lilo-$label"
  3245.             ;;
  3246.         165)
  3247.             label="bsd"
  3248.             ;;
  3249.         169)
  3250.             label="NetBSD"
  3251.             ;;
  3252.         esac
  3253.     else
  3254.         # propose "linux" as label if it looks like our kernel
  3255.         if [ -n "`echo $1 | sed -n '/^\/boot\/vmlinuz/p'`" ]; then
  3256.             label="linux"
  3257.         elif [ "$1" = "/vmlinuz" ]; then
  3258.             label="linux"
  3259.         fi
  3260.     fi
  3261.     sed -n '/label[ ]*=/s/^.*label[ ]*=[ ]*\(.*\)$/\1/p' $DIR_TARGET/$FILE_LILO_CONF.tmp | fgrep -x $label > /dev/null
  3262.     if [ $? -eq 0 ]; then
  3263.         label=
  3264.     fi
  3265.  
  3266.     while [ 1 ]; do
  3267.         Ask_String LILO_LABEL "$label" || return 1
  3268.         if [ -z "$ANSWER" ]; then
  3269.             continue
  3270.         fi
  3271.         label="$ANSWER"
  3272.         # CHECK: test whether label already exists
  3273.         sed -n '/label[ ]*=/s/^.*label[ ]*=[ ]*\(.*\)$/\1/p' $DIR_TARGET/$FILE_LILO_CONF.tmp | fgrep -x $label > /dev/null
  3274.         if [ $? -eq 0 ]; then
  3275.             Warn ":WARN_LABEL_ALREADY_USED:"
  3276.             continue
  3277.         else
  3278.             cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  3279.     label = $label
  3280. EOF
  3281.             return 0
  3282.         fi
  3283.     done
  3284. }
  3285.  
  3286. Ask_LILO_Params()
  3287. {
  3288.   local append="$1"
  3289.  
  3290.   Debug "append = <$append>"
  3291.   # remove quotes from any previous append string
  3292.   append="`echo $append | cut -d'\"' -f 2`"
  3293.   Debug "append = <$append>"
  3294.   Ask_String LILO_PARAMS "$append" || return 1
  3295.   if [ -n "$ANSWER" ]; then
  3296.     echo "    append = \"$ANSWER\"" >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  3297.   fi
  3298.   return 0
  3299. }
  3300.  
  3301. Ask_LILO_Initrd()
  3302. {
  3303.   local initrd_file=/boot/initrd.gz
  3304.  
  3305.   if [ ! -f $DIR_TARGET/$initrd_file ]; then
  3306.     initrd_file=
  3307.     ANSWER=
  3308.     return 0
  3309.   fi
  3310.  
  3311.   Ask_String LILO_INITRD "$initrd_file" || return 1
  3312.   return 0
  3313. }
  3314.  
  3315. Ask_LILO_Entry()
  3316. {
  3317.   local build_function="$1"
  3318.   local text_label="$2"
  3319.   local root_part="$3"
  3320.   local image=
  3321.   local entry=image
  3322.   local label=
  3323.   local use_initrd=
  3324.   local append=
  3325.  
  3326.   Choose --build "$build_function $DIR_TARGET" $text_label || return 1
  3327.   if [ "$ANSWER" = "END" ]; then
  3328.     return 0
  3329.   fi
  3330.   image="$ANSWER"
  3331.   echo "$image" | fgrep '/dev/' > /dev/null
  3332.   if [ $? -eq 0 ]; then
  3333.     entry=other
  3334.     cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  3335.  
  3336. $entry = $image
  3337. EOF
  3338.     Ask_LILO_Label $image || continue
  3339.     Do_Add_LILO_Table $image
  3340.   else
  3341.     entry=image
  3342.     cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  3343.  
  3344. $entry = $image
  3345. EOF
  3346.     Ask_LILO_Initrd || continue
  3347.     if [ -n "$ANSWER" ]; then
  3348.       echo "    initrd = \"$ANSWER\"" >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  3349.       use_initrd=true
  3350.       # on newer kernels we don't need this any more
  3351.       #append="load_ramdisk=1 ramdisk_size=2880"
  3352.       append=""
  3353.     else
  3354.       append=""
  3355.     fi
  3356.     Ask_LILO_Label $image || continue
  3357.     cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  3358.     root = $root_part
  3359.     read-only
  3360. EOF
  3361.     Ask_LILO_Params "$append"
  3362.   fi
  3363.   return 0
  3364. }
  3365.  
  3366.  
  3367. Menu_Config_GRUB_HD()
  3368. {
  3369.     local root_part
  3370.  
  3371.     # get root partition
  3372.     if [ "$DIR_TARGET" != "/" ]; then
  3373.         root_part="$CONF_INSTALL_ROOT"
  3374.     else
  3375.         root_part="`rdev | cut -d' ' -f 1`"
  3376.     fi
  3377.     Do_Store CONF_INSTALL_ROOT "$root_part"
  3378.     Do_Store CONF_INSTALL_LILO "$root_part"
  3379.     return 0
  3380. }
  3381.  
  3382.  
  3383. Menu_Config_LILO_HD()
  3384. {
  3385.     local default_mbr=
  3386.     local default_target=
  3387.     local lilo_in_mbr=
  3388.     local mode=
  3389.     local os2_bootmgr=
  3390.     local root_part=
  3391.     local root_part_id=
  3392.     local root_part_type=
  3393.     local target=
  3394.  
  3395.     # FIXME: shortcut in case we use GRUB
  3396.     if [ -x $DIR_TARGET/usr/sbin/grub ]; then
  3397.         Menu_Config_GRUB_HD
  3398.         return 0
  3399.     fi
  3400.  
  3401.     Do_Analyse_Boot_Setup > $DIR_LST_TMP/bootsetup
  3402.     Browse2 $DIR_LST_TMP/bootsetup ANALYSE_BOOT_SETUP || return 1
  3403.  
  3404.     # -- outermost loop start --
  3405.     while [ 1 ]; do
  3406.  
  3407.         # -- target loop start -- (not indended)
  3408.         while [ 1 ]; do
  3409.     # get first mbr
  3410.     default_mbr="`sysinfo --tag -C MBR --disk`"
  3411.     Debug "default_mbr = <$default_mbr>"
  3412.  
  3413.     # get root partition
  3414.     if [ "$DIR_TARGET" != "/" ]; then
  3415.         root_part="$CONF_INSTALL_ROOT"
  3416.     else
  3417.         root_part="`rdev | cut -d' ' -f 1`"
  3418.     fi
  3419.     Debug "root_part = <$root_part>"
  3420.  
  3421.     # get root partition type
  3422.     root_part_id="`Get_Partition_Info --id $root_part`"
  3423.     Debug "root_part_id = <$root_part_id>"
  3424.     case $partid in
  3425.     1|4|6|11|12|14)
  3426.         root_part_type=msdos
  3427.         ;;
  3428.     131)    
  3429.         root_part_type=ext2
  3430.         ;;
  3431.     esac
  3432.     Debug "root_part_type = <$root_part_type>"
  3433.  
  3434.     # check MBR for LILO
  3435.     Check_LILO
  3436.     if [ $? -eq 0 -a "$ANSWER" = "LILO" ]; then
  3437.         lilo_in_mbr=true
  3438.         Debug "detected LILO in $default_mbr"
  3439.     fi
  3440.  
  3441.     # check for OS/2 boot manager
  3442.     os2_bootmgr="`sysinfo --tag -C Bootmanager --partition | sed -n '1p'`"
  3443.     if [ -n "$os2_bootmgr" ]; then
  3444.         Debug "detected OS/2 Bootmanager in $os2_bootmgr"
  3445.     fi
  3446.  
  3447.     # try to offer a smart default target
  3448.     default_target="`Get_Val CONF_INSTALL_LILO`"
  3449.     if [ -z "$default_target" ]; then
  3450.         if [ -n "$lilo_in_mbr" ]; then
  3451.             # bad idea to use the MBR, but if they are used to it...
  3452.             default_target="$default_mbr"
  3453.         else
  3454.             # use root partition per default
  3455.             default_target="$root_part"
  3456.             # use other partition if root is MSDOS
  3457.             if [ "$root_part_type" = "msdos" ]; then
  3458.                 default_target=OTHER
  3459.                 # do not allow LILO on msdos partitions
  3460.                 Msg ":INFO_NO_LILO_ON_UMSDOS:"
  3461.             else
  3462.                 # check if root_part is a primary partition on 1st disk
  3463.                 if [ -z "`sysinfo --tag -C LILOACTIVE --partition | fgrep -x $root_part`" ]; then
  3464.                     # without OS/2 bootmanager use the MBR
  3465.                     if [ -z "$os2_bootmgr" ]; then
  3466.                         default_target="$default_mbr"
  3467.                     fi
  3468.                 fi
  3469.             fi
  3470.         fi
  3471.     fi
  3472.     Debug "default_target = <$default_target>"
  3473.  
  3474.     Choose --build "Build_LILO_TARGET $root_part $root_part_type" LILO_TARGET $default_target || return 1
  3475.     target="$ANSWER"
  3476.  
  3477.     case $target in
  3478.     /dev/hda|/dev/sda)
  3479.         mode=MBR
  3480.         ;;
  3481.     $root_part)
  3482.         mode=ROOT
  3483.         ;;
  3484.     OTHER)
  3485.         mode=OTHER
  3486.         Choose --build "Build_LILO_TARGET_OTHER $root_part" LILO_TARGET_OTHER || continue
  3487.         target="$ANSWER"
  3488.         ;;
  3489.     /dev/fd0H1440|/dev/fd0)
  3490.         mode=FLOPPY
  3491.         ;;
  3492.     NONE)
  3493.         return 0
  3494.         ;;
  3495.     esac
  3496.  
  3497.     # BEGIN: sanity checks
  3498.  
  3499.     if [ "$mode" = "MBR" -o "$mode" = "FLOPPY" ]; then
  3500.         break
  3501.     fi
  3502.  
  3503.     # warn if a LILO is detected in the MBR
  3504.     if [ -n "$lilo_in_mbr" ]; then
  3505.         Warn ":WARN_LILO_FOUND_IN_MBR:" || continue
  3506.     fi
  3507.     break
  3508.  
  3509.     # END: sanity checks
  3510.  
  3511.         # -- target loop end --
  3512.         done
  3513.  
  3514.         # -- default entry loop start --
  3515.         while [ 1 ]; do
  3516.             again=true
  3517.             Do_Create_Generic_LILO_Conf $target
  3518.             Ask_LILO_Entry Build_LILO_ENTRY LILO_DEFAULT_ENTRY $root_part || break
  3519.  
  3520.             again=
  3521.             break
  3522.         # -- default loop end --
  3523.         done
  3524.         if [ -n "$again" ]; then
  3525.             continue
  3526.         fi
  3527.         cat << EOF >> $DIR_TARGET/$FILE_LILO_CONF.tmp
  3528.  
  3529. #
  3530. # additional entries
  3531. #
  3532.  
  3533. EOF
  3534.  
  3535.         # -- alternate loop start --
  3536.         while [ 1 ]; do
  3537.             again=true
  3538.             Ask_LILO_Entry Build_LILO_ADD_ENTRY LILO_ADD_ENTRY $root_part || break
  3539.             if [ "$ANSWER" = "END" ]; then
  3540.                 again=
  3541.                 break
  3542.             fi
  3543.         # -- alternate loop end --
  3544.         done
  3545.         if [ -n "$again" ]; then
  3546.             continue
  3547.         fi
  3548.  
  3549.         Browse2 $DIR_TARGET/$FILE_LILO_CONF.tmp LILO_CONF || continue
  3550.         Ask_Bool INSTALL_LILO || continue
  3551.         if [ "$ANSWER" != "0" ]; then
  3552.             continue
  3553.         fi
  3554.         cp -a $DIR_TARGET/$FILE_LILO_CONF.tmp $DIR_TARGET/$FILE_LILO_CONF || continue
  3555.         if Is_SPARC ; then
  3556.             cp -a $DIR_TARGET/$FILE_LILO_CONF $DIR_TARGET/etc/silo.conf
  3557.         fi
  3558.  
  3559.         Do_Install_LILO || continue
  3560.  
  3561.         if [ "$mode" = "MBR" -o "$mode" = "FLOPPY" ]; then
  3562.             break
  3563.         fi
  3564.  
  3565.         # warn if target is no primary on 1st disk and no OS/2 Bootmanager
  3566.         if [ -z "`sysinfo --tag -C LILOACTIVE --partition | fgrep -x $target`" -a -z "$os2_bootmgr" ]; then
  3567.             Warn ":WARN_LILO_NOT_ACTIVE_AND_NO_BOOTMANAGER:" || continue
  3568.         else
  3569.             if [ -z "`sysinfo --tag -C active --partition | fgrep -x $target`" ]; then
  3570.                 Ask_Bool --pretext "$target ; " ACTIVATE_PARTITION || continue
  3571.                 if [ "$ANSWER" = "0" ]; then
  3572.                     Do_Activate_Partition $target || continue
  3573.                 else
  3574.                     Warn ":WARN_LILO_NOT_ACTIVE:" || continue
  3575.                 fi
  3576.             fi
  3577.         fi
  3578.         break
  3579.     done
  3580.     # -- outermost loop end --
  3581.     Do_Store CONF_INSTALL_LILO "$target"
  3582.     return 0
  3583. }
  3584.  
  3585. Menu_Config_Boot()
  3586. {
  3587.     mount | fgrep ' / ' | fgrep umsdos > /dev/null
  3588.     if [ $? -eq 0 ]; then
  3589.         Msg ":INFO_NO_LILO_ON_UMSDOS:"
  3590.         return 1
  3591.     fi    
  3592.  
  3593.     while [ 1 ]; do
  3594.         $CMD_BOX --help ":MENU_CONFIG_BOOT_HELP:" \
  3595. --title ":MENU_CONFIG_BOOT_TITLE:" \
  3596. --menu ":MENU_CONFIG_BOOT_TEXT:" \
  3597. "Menu_Config_LILO_HD" ":MENU_CONFIG_LILO_HD:" 2> $FILE_TMP_ANSWER || return 1
  3598.         COMMAND="`cat $FILE_TMP_ANSWER`"
  3599.         $COMMAND
  3600.     done
  3601. }
  3602.  
  3603. # libLSTbox - box call library shared between several scripts
  3604. #
  3605. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  3606. #
  3607.  
  3608. # Ask what goal build_function
  3609. Ask()
  3610. {
  3611.     FUNC_NAME=Ask
  3612.     local cmd=$FILE_TMP_COMMAND
  3613.     local what="$1"
  3614.     local goal="$2"
  3615.     local ans=/tmp/LST/ans
  3616.     local prefix=
  3617.     local defval=
  3618.  
  3619.     echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  3620.  
  3621.     shift 2
  3622.  
  3623.     if [ "X$1" = "X--default" ]; then
  3624.         defval="$2"
  3625.         shift 2
  3626.     fi
  3627.  
  3628.     case $what in
  3629.     bool|string)
  3630.         prefix=ASK
  3631.         defval="$1"
  3632.         ;;
  3633.     one)
  3634.         prefix=CHOOSE
  3635.         ;;
  3636.     menu)
  3637.         prefix=MENU
  3638.         what=one
  3639.         ;;
  3640.     esac
  3641.  
  3642.     cat << EOF > $cmd
  3643. #!/bin/sh
  3644.  
  3645. $CMD_BOX --title ":${prefix}_${goal}_TITLE:" \\
  3646.     --help ":${prefix}_${goal}_HELP:" \\
  3647.     --default "${defval}" \\
  3648.     --${what} ":${prefix}_${goal}_TEXT:" \\
  3649. EOF
  3650.  
  3651.     case $what in
  3652.     one)
  3653.         $@ >> $cmd
  3654.         ;;
  3655.     esac
  3656.  
  3657.     echo "2> $ans" >> $cmd
  3658.     chmod 755 $cmd
  3659.  
  3660.     # log command if requested
  3661.     Log_Cmd
  3662.  
  3663.     $cmd || return 1
  3664.     export ANSWER="`cat $ans`"
  3665.     return 0
  3666. }
  3667.  
  3668. #
  3669. # libLSTnew
  3670. #
  3671.  
  3672. # Ask what goal build_function
  3673. Ask2()
  3674. {
  3675.     FUNC_NAME=Ask
  3676.     local cmd=$FILE_TMP_COMMAND
  3677.     local what="$1"
  3678.     local goal="$2"
  3679.     local ans=$FILE_TMP_ANSWER
  3680.     local prefix=
  3681.     local defval=
  3682.     local other=
  3683.     local pretext=
  3684.     local posttext=
  3685.  
  3686.     echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  3687.  
  3688.     shift 2
  3689.  
  3690.     while [ 1 ]; do
  3691.         if [ $# -eq 0 ]; then
  3692.             break
  3693.         fi
  3694.         if [ "X$1" = "X--other" ]; then
  3695.             other=true
  3696.             shift 1
  3697.         elif [ "X$1" = "X--default" ]; then
  3698.             defval="$2"
  3699.             shift 2
  3700.         elif [ "X$1" = "X--pretext" ]; then
  3701.             pretext="$2"
  3702.             shift 2
  3703.         elif [ "X$1" = "X--posttext" ]; then
  3704.             posttext="$2"
  3705.             shift 2
  3706.         else
  3707.             break
  3708.         fi
  3709.     done
  3710.  
  3711.     case $what in
  3712.     bool|string)
  3713.         prefix=ASK
  3714.         if [ -z "$defval" ]; then
  3715.             defval="$1"
  3716.         fi
  3717.         ;;
  3718.     one)
  3719.         prefix=CHOOSE
  3720.         ;;
  3721.     menu)
  3722.         prefix=MENU
  3723.         what=one
  3724.         ;;
  3725.     esac
  3726.  
  3727.     if [ "$what" = "one" ]; then
  3728.         rm -f ${cmd}.itm
  3729.         $@ > ${cmd}.itm
  3730.         if [ ! -s ${cmd}.itm ]; then
  3731.             Debug "Error: empty list: $@"
  3732.             what=string
  3733.             prefix=ASK
  3734.         fi
  3735.     fi
  3736.  
  3737.     cat << EOF > $cmd
  3738. #!/bin/sh
  3739.  
  3740. $CMD_BOX --title ":${prefix}_${goal}_TITLE:" \\
  3741.     --help ":${prefix}_${goal}_HELP:" \\
  3742.     --default "${defval}" \\
  3743.     --${what} "${pretext}:${prefix}_${goal}_TEXT:${posttext}" \\
  3744. EOF
  3745.  
  3746.     if [ "$what" = "one" ]; then
  3747.         if [ "$other" = "true"  ]; then
  3748.             echo "\"OTHER\" \":${prefix}_${goal}_OTHER:\" \\" >> ${cmd}
  3749.         fi
  3750.         if [ "$none" = "true"  ]; then
  3751.             echo "\"NONE\" \":${prefix}_${goal}_NONE:\" \\" >> ${cmd}
  3752.         fi
  3753.         cat ${cmd}.itm >> ${cmd}
  3754.     fi
  3755.  
  3756.     echo "2> $ans" >> $cmd
  3757.     chmod 755 $cmd
  3758.  
  3759.     # log command if requested
  3760.     Log_Cmd
  3761.  
  3762.     $cmd || return 1
  3763.     export ANSWER="`cat $ans`"
  3764.     return 0
  3765. }
  3766.  
  3767.  
  3768. Get_Module_Line()
  3769. {
  3770.     sed -n "/^%[^%]*%$2%/p" $1
  3771. }
  3772.  
  3773. Get_Module_Param_Num()
  3774. {
  3775.     Get_Module_Line $1 $2 | cut -d'%' -f $NUM_POS
  3776. }
  3777.  
  3778. List_Param_Of_Module()
  3779. {
  3780.     local num
  3781.     local i=0
  3782.     local pos="`do_calc $NUM_POS + 1`"
  3783.  
  3784.     num="`Get_Module_Param_Num $1 $2`"
  3785.     if [ -z "$num" -o "$num" = '?' ]; then
  3786.         num=unknown
  3787.         Debug 'Number of insmod parameters is unknown !'
  3788.         return 1
  3789.     elif [ "$num" = "0" ]; then
  3790.         num=none
  3791.         Debug "No insmod params."
  3792.         return 0
  3793.     fi
  3794.  
  3795.     while [ 1 ]; do
  3796.         i="`do_calc $i + 1`"
  3797.         if [ $i -gt $num ]; then
  3798.             break
  3799.         fi
  3800.         parm="`Get_Module_Line $1 $2 | cut -d'%' -f $pos`"
  3801.         echo "$parm"
  3802.         pos="`do_calc $pos + $NUM_PER_PARAM`"
  3803.     done
  3804. }
  3805.  
  3806. Build_Param_Of_Module()
  3807. {
  3808.     local params
  3809.     local val
  3810.     local i
  3811.  
  3812.     params="`List_Param_Of_Module $1 $2`"
  3813.     if [ $? -ne 0 ]; then
  3814.         return 1
  3815.     fi
  3816.     if [ -z "$params" ]; then
  3817.         return 0
  3818.     fi
  3819.     echo "\"DONE\" \":CHOOSE_PARAM_OF_MODULE_DONE:\" \\"
  3820.     echo "\"OTHER\" \":CHOOSE_PARAM_OF_MODULE_OTHER:\" \\"
  3821.     for i in $params ; do
  3822.         val="`get_val -f $FILE_VALUES_SEL Value_Of_Param%${2}%${i}%current`"
  3823.         echo "\"$i\" \"$i [${val}]\" \\"
  3824.     done
  3825. }
  3826.  
  3827. Build_Value_Of_Param()
  3828. {
  3829.     local num
  3830.     local i=0
  3831.     local pos="`do_calc $NUM_POS + 1`"
  3832.     local posvals
  3833.     local posdef
  3834.     local values
  3835.     local defval
  3836.     local val
  3837.  
  3838.     num="`Get_Module_Param_Num $1 $2`"
  3839.     if [ -z "$num" -o "$num" = '?' ]; then
  3840.         num=unknown
  3841.         Debug 'Number of insmod parameters is unknown !'
  3842.         return 1
  3843.     elif [ "$num" = "0" ]; then
  3844.         num=none
  3845.         Debug "No insmod params."
  3846.         return 0
  3847.     fi
  3848.     Debug "num = $num"
  3849.  
  3850.     while [ 1 ]; do
  3851.         i="`do_calc $i + 1`"
  3852.         if [ $i -gt $num ]; then
  3853.             Debug "param $3 not found."
  3854.             break
  3855.         fi
  3856.         parm="`Get_Module_Line $1 $2 | cut -d'%' -f $pos`"
  3857.         if [ "$parm" != "$3" ]; then
  3858.             pos="`do_calc $pos + $NUM_PER_PARAM`"
  3859.             continue
  3860.         fi
  3861.         posvals="`do_calc $pos + 2`"
  3862.         Debug "posvals = <$posvals>"
  3863.         posdef="`do_calc $pos + 3`"
  3864.         Debug "posdef = <$posdef>"
  3865.         values="`Get_Module_Line $1 $2 | cut -d'%' -f $posvals | sed 's/,/ /g'`"
  3866.         Debug "values = <$values>"
  3867.         defval="`Get_Module_Line $1 $2 | cut -d'%' -f $posdef`"
  3868.         Debug "defval = <$defval>"
  3869.         for val in $values ; do
  3870.             if [ "X$val" = "X$defval" ]; then
  3871.                 echo "\"$val\" \"$val [default]\" \\"
  3872.             else
  3873.                 echo "\"$val\" \"$val\" \\"
  3874.             fi
  3875.         done
  3876.         break
  3877.     done
  3878. }
  3879.  
  3880. Choose_Param_Of_Module()
  3881. {
  3882.     local modname="$1"
  3883.     local modparam
  3884.  
  3885.     shift 1
  3886.     if [ $# -gt 0 ]; then
  3887.         modparam="$1"
  3888.     else
  3889.         modparam="`get_val -f $FILE_VALUES_SEL Param_Of_Module%${modname}%current`"
  3890.     fi
  3891.     Ask2 one PARAM_OF_MODULE --pretext "module=$modname ; ; " --default "$modparam" Build_Param_Of_Module $FILE_MODULES_DATA $modname || return 1
  3892.     modparam="$ANSWER"
  3893.     set_val -f $FILE_VALUES_SEL Param_Of_Module%${modname}%current "${modparam}"
  3894.     return 0
  3895. }
  3896.  
  3897.  
  3898. Choose_Value_Of_Param()
  3899. {
  3900.     local modname="$1"
  3901.     local modparam="$2"
  3902.     local paramval
  3903.  
  3904.     shift 2
  3905.     if [ $# -gt 0 ]; then
  3906.         paramval="$1"
  3907.     else
  3908.         paramval="`get_val -f $FILE_VALUES_SEL Value_Of_Param%${modname}%${modparam}%current`"
  3909.     fi
  3910.     Ask2 one VALUE_OF_PARAM --other --pretext "module=$modname ; parameter=$modparam ; ; " --default "$paramval" Build_Value_Of_Param $FILE_MODULES_DATA $modname $modparam || return 1
  3911.     paramval="$ANSWER"
  3912.     if [ "$paramval" = "OTHER" ]; then
  3913.         paramval="`get_val -f $FILE_VALUES_SEL Value_Of_Param%${modname}%${modparam}%current`"
  3914.         Ask2 string MODULE_PARAM --other --pretext "module=$modname ; parameter=$modparam ; ; " --default "$paramval" || return 1
  3915.         paramval="$ANSWER"
  3916.     fi
  3917.     set_val -f $FILE_VALUES_SEL Value_Of_Param%${modname}%${modparam}%current "${paramval}"
  3918.     return 0
  3919. }
  3920.  
  3921. Ask_Module_Param()
  3922. {
  3923.     local modname="$1"
  3924.     local params
  3925.     local insmod_params="`get_val -f $FILE_VALUES_SEL Module_Params%${modname}%current`"
  3926.  
  3927.     Ask2 string MODULE_PARAM "$insmod_params" || return 1
  3928.     insmod_params="$ANSWER"
  3929.     set_val -f $FILE_VALUES_SEL Module_Params%${modname}%current "${insmod_params}"
  3930.     return 0
  3931. }
  3932.  
  3933. Menu_Module_Param()
  3934. {
  3935.     local modname="$1"
  3936.     local modparam
  3937.     local paramval
  3938.     local params
  3939.     local insmod_params
  3940.  
  3941.     params="`List_Param_Of_Module $FILE_MODULES_DATA $modname`"
  3942.     if [ -z "$params" ]; then
  3943.         Ask_Module_Param $modname || return 1
  3944.         insmod_params="$ANSWER"
  3945.     else
  3946.         while [ 1 ]; do
  3947.             Choose_Param_Of_Module "$modname" || return 1
  3948.             modparam="$ANSWER"
  3949.             if [ "$modparam" = "OTHER" ]; then
  3950.                 Ask_Module_Param $modname || continue
  3951.                 insmod_params="$ANSWER"
  3952.                 break
  3953.             fi
  3954.             if [ "$modparam" != "DONE" ]; then
  3955.                 Choose_Value_Of_Param "$modname" "$modparam" || continue
  3956.                 paramval="$ANSWER"
  3957.             else
  3958.                 insmod_params=
  3959.                 for modparam in `List_Param_Of_Module $FILE_MODULES_DATA $modname` ; do
  3960.                     paramval="`get_val -f $FILE_VALUES_SEL Value_Of_Param%${modname}%${modparam}%current`"
  3961.                     if [ -n "$paramval" ]; then
  3962.                         insmod_params="$insmod_params $modparam=${paramval}"
  3963.                     fi
  3964.                 done
  3965.                 break
  3966.             fi
  3967.         done
  3968.     fi
  3969.     ANSWER="$insmod_params"
  3970.     return 0
  3971. }
  3972.  
  3973.  
  3974. # Ask_Bool ( [--pretext PRETEXT] [--prehelp PREHELP] [--help ALTERNATE_HELP] [--text ALTERNATE_TEXT] VARNAME [DEFAULTVAL] )
  3975. #       Just ask a yes/no question
  3976. #
  3977. Ask_Bool()
  3978. {
  3979.     FUNC_NAME=Ask_Bool
  3980.     export ANSWER=
  3981.     local retval=
  3982.     local help=
  3983.     local text=
  3984.     local prehelp=
  3985.     local pretext=
  3986.  
  3987.     echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  3988.  
  3989.     if [ $# -lt 1 ]; then
  3990.         Panic "got $# instead of at least 1 arg!"
  3991.     fi
  3992.  
  3993.     # look for pretext
  3994.     if [ $# -gt 2 ]; then
  3995.         if [ "$1" = '--pretext' ]; then
  3996.             pretext="$2"
  3997.             shift 2
  3998.         fi
  3999.     fi
  4000.  
  4001.     # look for prehelp
  4002.     if [ $# -gt 2 ]; then
  4003.         if [ "$1" = '--prehelp' ]; then
  4004.             prehelp="$2"
  4005.             shift 2
  4006.         fi
  4007.     fi
  4008.  
  4009.     # look for alternate help
  4010.     if [ $# -gt 2 ]; then
  4011.         if [ "$1" = '--help' ]; then
  4012.             help="$2"
  4013.             shift 2
  4014.         fi
  4015.     fi
  4016.  
  4017.     # look for alternate text
  4018.     if [ $# -gt 2 ]; then
  4019.         if [ "$1" = '--text' ]; then
  4020.             text="$2"
  4021.             shift 2
  4022.         fi
  4023.     fi
  4024.  
  4025.     if [ -z "$help" ]; then
  4026.         help=":ASK_$1_HELP:"
  4027.     fi
  4028.  
  4029.     if [ -z "$text" ]; then
  4030.         text=":ASK_$1_TEXT:"
  4031.     fi
  4032.  
  4033.     # build command header
  4034.     echo "$CMD_BOX --help \"${prehelp}${help}\" --title \":ASK_$1_TITLE:\" --bool \"${pretext}${text}\" \\" > $FILE_TMP_COMMAND
  4035.  
  4036.     # append default value if available
  4037.     if [ $# -gt 1 ]; then
  4038.         echo "--default \"$2\" \\" >> $FILE_TMP_COMMAND
  4039.     fi
  4040.  
  4041.     # build command trailer
  4042.     echo "2> $FILE_TMP_ANSWER" >> $FILE_TMP_COMMAND
  4043.     chmod 755 $FILE_TMP_COMMAND
  4044.  
  4045.     # log command if requested
  4046.     Log_Cmd
  4047.  
  4048.     # execute command
  4049.     sh $FILE_TMP_COMMAND
  4050.     retval=$?
  4051.     if [ $retval -eq 0 ]; then
  4052.         ANSWER="`cat $FILE_TMP_ANSWER`"
  4053.     fi
  4054.     rm -f $FILE_TMP_COMMAND
  4055.     rm -f $FILE_TMP_ANSWER
  4056.     return $retval
  4057. }
  4058.  
  4059. # Ask_String ( [--pretext PRETEXT] VARNAME [DEFAULTVAL] )
  4060. #
  4061. # ask for a string
  4062. #
  4063. Ask_String()
  4064. {
  4065.     FUNC_NAME=Ask_String
  4066.     export ANSWER=
  4067.     local retval=
  4068.     local text=
  4069.     local help=
  4070.     local pretext=
  4071.     local prehelp=
  4072.  
  4073.     echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  4074.  
  4075.     if [ $# -lt 1 ]; then
  4076.         Panic "got $# instead of at least 1 arg!"
  4077.     fi
  4078.  
  4079.     if [ $# -gt 2 -a "$1" = '--pretext' ]; then
  4080.         pretext="$2"
  4081.         shift 2
  4082.     fi
  4083.  
  4084.     if [ $# -gt 2 -a "$1" = '--prehelp' ]; then
  4085.         prehelp="$2"
  4086.         shift 2
  4087.     fi
  4088.  
  4089.     if [ $# -gt 2 -a "$1" = '--help' ]; then
  4090.         help="$2"
  4091.         shift 2
  4092.     else
  4093.         help=":ASK_$1_HELP:"
  4094.     fi
  4095.  
  4096.     text=":ASK_$1_TEXT:"
  4097.  
  4098.     # if [ $# -gt 1 ]; then
  4099.     #    $CMD_BOX --default "$2" --help "${prehelp}${help}" --title ":ASK_$1_TITLE:" --string "${pretext}${text}" 2> $FILE_TMP_ANSWER
  4100.     # else
  4101.     #     $CMD_BOX --help "${prehelp}${help}" --title ":ASK_$1_TITLE:" --string "${pretext}${text}" 2> $FILE_TMP_ANSWER
  4102.     # fi
  4103.     # retval=$?
  4104.  
  4105.     # build command header
  4106.     echo "$CMD_BOX --help \"${prehelp}${help}\" --title \":ASK_$1_TITLE:\" --string \"${pretext}${text}\" \\" > $FILE_TMP_COMMAND
  4107.  
  4108.     # append default value if available
  4109.     if [ $# -gt 1 ]; then
  4110.         echo "--default \"$2\" \\" >> $FILE_TMP_COMMAND
  4111.     fi
  4112.  
  4113.     # build command trailer
  4114.     echo "2> $FILE_TMP_ANSWER" >> $FILE_TMP_COMMAND
  4115.     chmod 755 $FILE_TMP_COMMAND
  4116.  
  4117.     # log command if requested
  4118.     Log_Cmd
  4119.  
  4120.     # execute command
  4121.     sh $FILE_TMP_COMMAND
  4122.  
  4123.     retval=$?
  4124.     if [ $retval -eq 0 ]; then
  4125.         ANSWER="`cat $FILE_TMP_ANSWER`"
  4126.     else
  4127.         ANSWER=""
  4128.         Debug -D "Ask_String Output (Start)" 
  4129.         Debug -c cat $FILE_TMP_ANSWER
  4130.         Debug -D "Ask_String Output (End)" 
  4131.     fi
  4132.     rm -f $FILE_TMP_ANSWER
  4133.     return $retval
  4134. }
  4135.  
  4136. # Box ( TYPE [--var VAR] [--help HELP] [--text TEXT] [--title TITLE])
  4137. #            [--build ITMEMBUILDFUNCTION] [DEFAULTVAL])
  4138. #
  4139. # Box is a box frontend, returning answer in $ANSWER
  4140. #
  4141. #    box-types (TYPE):
  4142. #
  4143. # a) input boxes
  4144. #    bool
  4145. #    num
  4146. #    ip
  4147. #    string
  4148. #    one
  4149. #    menu
  4150. #    showlist
  4151. #    menulist
  4152. #
  4153. # b) output boxes
  4154. #    info
  4155. #    msg
  4156. #    browse
  4157. #    err
  4158. #    warn
  4159. #
  4160. # --var ask & set value of variable VAR
  4161. # --help replace standard-help with HELP
  4162. # --text replace standard-text with TEXT
  4163. # --title replace standard-title with TITLE
  4164. # --build use function BUILD to create itemlist
  4165. #
  4166.  
  4167. Box()
  4168. {
  4169.     FUNC_NAME=Box
  4170.     export ANSWER=
  4171.     local box_type=string
  4172.     local retval=
  4173.     local variable=BOX
  4174.     local title=
  4175.     local text=
  4176.     local help=
  4177.     local build=
  4178.     local defval=
  4179.     local file=
  4180.  
  4181.     echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  4182.  
  4183.     # process options
  4184.     if [ $# -eq 0 ]; then
  4185.         Panic "$FUNC_NAME: panic! no box type specified!"
  4186.     fi
  4187.  
  4188.     # get box_type
  4189.     box_type="$1"
  4190.     shift 1
  4191.  
  4192.     case $box_type in
  4193.     bool)
  4194.         prefix=BOOL ;;
  4195.     num|ip|string)
  4196.         prefix=ASK ;;
  4197.     one|showlist)
  4198.         prefix=CHOOSE ;;
  4199.     menu|sumlist)
  4200.         prefix=MENU ;;
  4201.     msg|info|browse)
  4202.         prefix=INFO ;;
  4203.     err)
  4204.         box_type=browse
  4205.         prefix=ERR ;;
  4206.     warn)
  4207.         box_type=msg
  4208.         prefix=WARN ;;
  4209.     *)
  4210.         Panic "$FUNC_NAME: panic! invalid box type specified!";;
  4211.     esac
  4212.  
  4213.     # set standard help
  4214.     title=":${prefix}_${variable}_TITLE:"
  4215.     text=":${prefix}_${variable}_TEXT:"
  4216.     help=":${prefix}_${variable}_HELP:"
  4217.  
  4218.     while [ 1 ]; do
  4219.         if [ $# -eq 0 ]; then
  4220.             break
  4221.         elif [ $# -gt 1 ]; then
  4222.             # options that take arguments
  4223.             case $1 in
  4224.             --var)
  4225.                 variable="$2"
  4226.                 title=":${prefix}_${variable}_TITLE:"
  4227.                 text=":${prefix}_${variable}_TEXT:"
  4228.                 help=":${prefix}_${variable}_HELP:"
  4229.                 shift 2
  4230.                 continue;;
  4231.             --help)
  4232.                 help="$2"
  4233.                 shift 2
  4234.                 continue;;
  4235.             --title)
  4236.                 title="$2"
  4237.                 shift 2
  4238.                 continue;;
  4239.             --text)
  4240.                 text="$2"
  4241.                 shift 2
  4242.                 continue;;
  4243.             --build)
  4244.                 build="$2"
  4245.                 shift 2
  4246.                 continue;;
  4247.             esac
  4248.         else
  4249.             # flags that take no arguments
  4250.             if [ $# -eq 1 ]; then
  4251.                 # last argument is a default value or a file to browse
  4252.                 if [ "$box_type" = "browse" ]; then
  4253.                     file="$1"
  4254.                     shift 1
  4255.                     continue
  4256.                 else
  4257.                     defval="$1"
  4258.                     shift 1
  4259.                     continue
  4260.                 fi
  4261.             fi
  4262.         fi
  4263.         Panic "$FUNC_NAME: panic! invalid arguments $* !"
  4264.     done
  4265.  
  4266.     # command header
  4267.     echo -n "$CMD_BOX " > $FILE_TMP_COMMAND
  4268.  
  4269.     # command options
  4270.     if [ -n "$help" ]; then
  4271.         echo "--help \"$help\" \\" >> $FILE_TMP_COMMAND
  4272.     fi
  4273.     if [ -n "$title" ]; then
  4274.         echo "--title \"$title\" \\" >> $FILE_TMP_COMMAND
  4275.     fi
  4276.     if [ "$box_type" = "browse" ]; then
  4277.         echo "--text \"$text\" \\" >> $FILE_TMP_COMMAND
  4278.         echo "--browse $file \\" >> $FILE_TMP_COMMAND
  4279.     else
  4280.         echo "--$box_type \"$text\" \\" >> $FILE_TMP_COMMAND
  4281.     fi
  4282.     if [ -n "$defval" ]; then
  4283.         echo "--default \"$defval\" \\" >> $FILE_TMP_COMMAND
  4284.     fi
  4285.  
  4286.     # command items
  4287.     if [ -n "$build" ]; then
  4288.         # call build-function to build menu items
  4289.         $build > $FILE_TMP_MSG
  4290.         if [ -s $FILE_TMP_MSG ]; then
  4291.             cat $FILE_TMP_MSG >> $FILE_TMP_COMMAND
  4292.             rm -f $FILE_TMP_MSG
  4293.         else
  4294.             rm -f $FILE_TMP_COMMAND
  4295.             rm -f $FILE_TMP_ANSWER
  4296.             Panic "$FUNC_NAME: panic! empty list of items!"
  4297.         fi
  4298.     fi
  4299.  
  4300.     # command trailer
  4301.     echo "2> $FILE_TMP_ANSWER" >> $FILE_TMP_COMMAND
  4302.     chmod 755 $FILE_TMP_COMMAND
  4303.  
  4304.     # log command if requested
  4305.     Log_Cmd
  4306.  
  4307.     # execute command
  4308.     sh $FILE_TMP_COMMAND
  4309.     retval=$?
  4310.     if [ "$box_type" = "info" ]; then
  4311.         sleep 1
  4312.     fi
  4313.     if [ $retval -eq 0 ]; then
  4314.         if [ "$box_type" != "sumlist" ]; then
  4315.             ANSWER="`cat $FILE_TMP_ANSWER`"
  4316.             rm -f $FILE_TMP_ANSWER
  4317.         fi
  4318.     fi
  4319.     rm -f $FILE_TMP_COMMAND
  4320.     return $retval
  4321. }
  4322.  
  4323. Browse()
  4324. {
  4325.   FUNC_NAME=Browse
  4326.   echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  4327.   if [ $# -eq 2 ]; then
  4328.     Box browse --text "$2" $1 || return 1
  4329.     return 0
  4330.   else
  4331.     Box browse $1 || return 1
  4332.     return 0
  4333.   fi
  4334. }
  4335.  
  4336. Browse2()
  4337. {
  4338.   FUNC_NAME=Browse2
  4339.   echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  4340.   Box browse --var "$2" $1 || return 1
  4341.   return 0
  4342. }
  4343.  
  4344. # Choose ( [--none] [--other] [--prefix PREFIX] [--menutitle MENUTITLE] [--build MENUBUILDFUNCTION] VARNAME [CONFVARNAME] )
  4345. #
  4346. # ask for one out of many choices
  4347. #
  4348. Choose()
  4349. {
  4350.     FUNC_NAME=Choose
  4351.     export ANSWER=
  4352.     local retval=
  4353.     local box_type=one
  4354.     local one_flag=
  4355.     local other_flag=
  4356.     local none_flag=
  4357.     local menu_title=
  4358.     local build_function=
  4359.     local confval=
  4360.     local defval=
  4361.     local prefix=
  4362.  
  4363.     echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  4364.  
  4365.     while [ 1 ]; do
  4366.         if [ $# -gt 1 ]; then
  4367.             case $1 in 
  4368.             --build)
  4369.                 build_function="$2"
  4370.                 shift 2
  4371.                 continue;;
  4372.             --default)
  4373.                 defval="$2"
  4374.                 shift 2
  4375.                 continue;;
  4376.             --menutitle)
  4377.                 menu_title="$2"
  4378.                 shift 2
  4379.                 continue;;
  4380.             --prefix)
  4381.                 prefix="$2"
  4382.                 shift 2
  4383.                 continue;;
  4384.             --none)
  4385.                 none_flag=true
  4386.                 shift 1
  4387.                 continue;;
  4388.             --other)
  4389.                 other_flag=true
  4390.                 shift 1
  4391.                 continue;;
  4392.             --menu)
  4393.                 box_type=menu
  4394.                 shift 1
  4395.                 continue;;
  4396.             --multi)
  4397.                 box_type=multi
  4398.                 shift 1
  4399.                 continue;;
  4400.             --sumlist)
  4401.                 box_type=sumlist
  4402.                 shift 1
  4403.                 continue;;
  4404.             --onelist)
  4405.                 box_type=sumlist
  4406.                 one_flag='-O'
  4407.                 shift 1
  4408.                 continue;;
  4409.             --showlist)
  4410.                 box_type=showlist
  4411.                 shift 1
  4412.                 continue;;
  4413.             *)
  4414.                 break;;
  4415.             esac
  4416.         else
  4417.             break
  4418.         fi
  4419.     done
  4420.  
  4421.     if [ $# -lt 1 ]; then
  4422.         Panic "got $# instead of at least 1 args!"
  4423.     fi
  4424.  
  4425.     # build command header
  4426.     if [ -z "$prefix" ]; then
  4427.         case $box_type in
  4428.         one|showlist)
  4429.             prefix=CHOOSE
  4430.             ;;
  4431.         menu|sumlist|multi)
  4432.             prefix=MENU
  4433.             ;;
  4434.         esac
  4435.     fi
  4436.     echo "$CMD_BOX $one_flag --help \":${prefix}_$1_HELP:\" \\" > $FILE_TMP_COMMAND
  4437.     echo "--title \":${prefix}_$1_TITLE:\" \\" >> $FILE_TMP_COMMAND
  4438.     echo "--$box_type \":${prefix}_$1_TEXT:\" \\" >> $FILE_TMP_COMMAND
  4439.  
  4440.     # append default value if available
  4441.     if [ $# -gt 1 ]; then
  4442.         confval="`Get_Val $2`"
  4443.         if [ -n "$confval" ]; then
  4444.             echo "--default \"$confval\" \\" >> $FILE_TMP_COMMAND
  4445.         else
  4446.             echo "--default \"$2\" \\" >> $FILE_TMP_COMMAND
  4447.         fi
  4448.     elif [ -n "$defval" ]; then
  4449.         echo "--default \"$defval\" \\" >> $FILE_TMP_COMMAND
  4450.     fi
  4451.  
  4452.     if [ -n "$menu_title" ]; then
  4453.         echo "--menutitle \"$menu_title\" \\" >> $FILE_TMP_COMMAND
  4454.     fi
  4455.  
  4456.     rm -f $FILE_TMP_MSG
  4457.     if [ -n "$none_flag" ]; then
  4458.         Debug "NONE item allowed"
  4459.         echo "\"\" \":TYPE_$1_NONE:\" \\"  >> $FILE_TMP_MSG
  4460.     fi
  4461.     if [ -n "$other_flag" ]; then
  4462.         Debug "OTHER item allowed"
  4463.         Is_Expert && echo "\"other\" \":DEVICE_DIRECT:\" \\"  >> $FILE_TMP_MSG
  4464.     fi
  4465.  
  4466.     # build command header
  4467.     if [ -z "$build_function" ]; then
  4468.         build_function="List box $1"
  4469.     fi
  4470.  
  4471.     Debug "build item list with <$build_function>"
  4472.     # call build-function to build menu items
  4473.     $build_function >> $FILE_TMP_MSG
  4474.     if [ $? -ne 0 ]; then
  4475.         Debug "Error: return val != 0"
  4476.         Debug "Error: $ERROR"
  4477.         Error "$ERROR"
  4478.         return 1
  4479.     fi
  4480.     if [ -s $FILE_TMP_MSG ]; then
  4481.         cat $FILE_TMP_MSG >> $FILE_TMP_COMMAND
  4482.         rm -f $FILE_TMP_MSG
  4483.     else
  4484.         Debug "empty list. responsible command was"
  4485.         Debug -c cat $FILE_TMP_COMMAND 
  4486.         Error ":ERR_EMPTY_SELECTLIST:"
  4487.         return 1
  4488.     fi
  4489.  
  4490.     # build command trailer
  4491.     echo "2> $FILE_TMP_ANSWER" >> $FILE_TMP_COMMAND
  4492.     chmod 755 $FILE_TMP_COMMAND
  4493.  
  4494.     # log command if requested
  4495.     Log_Cmd
  4496.  
  4497.     # execute command
  4498.     Debug "Executing command: 'sh $FILE_TMP_COMMAND'"
  4499.     Debug -D "----- $FILE_TMP_COMMAND"
  4500.     Debug -c cat $FILE_TMP_COMMAND
  4501.     Debug -D "----- "
  4502.     sh $FILE_TMP_COMMAND
  4503.     retval=$?
  4504.     Debug "retval is $retval"
  4505.     if [ $retval -eq 0 ]; then
  4506.         ANSWER="`cat $FILE_TMP_ANSWER`"
  4507.         case $box_type in
  4508.         one)
  4509.             if [ "$ANSWER" = "other" ]; then
  4510.                 Ask_String $1 $confval
  4511.                 retval=$?
  4512.                 # ANSWER is set by Ask_String
  4513.             fi
  4514.             rm -f $FILE_TMP_ANSWER
  4515.             ;;
  4516.         menu|onelist|showlist)
  4517.             rm -f $FILE_TMP_ANSWER
  4518.             ;;
  4519.         sumlist|multi)
  4520.             # do not set ANSWER but keep $FILE_TMP_ANSWER
  4521.             ;;
  4522.         esac
  4523.     fi
  4524.     rm -f $FILE_TMP_COMMAND
  4525.     return $retval
  4526. }
  4527.  
  4528. Info()
  4529. {
  4530.   FUNC_NAME=Info
  4531.   echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  4532.   Box info --text "$@" || return 1
  4533.   return 0
  4534. }
  4535.  
  4536. Info_lite()
  4537. {
  4538.   FUNC_NAME=Info_lite
  4539.   echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  4540.   $CMD_BOX --info "$@" || return 1
  4541.   sleep 1
  4542.   return 0
  4543. }
  4544.  
  4545. List()
  4546. {
  4547.     local CD_DEV_LIST="aztcd cdu31a cdu535 cm206cd gscd mcd mcdx optcd sbpcd scd0 scd1 sjcd hda hdb hdc hdd arcd bpcd bpmcd dscd eicd epcd kicd oicd pwcd"
  4548.     local CUA_LIST="cua0 cua1 cua2 cua3"
  4549.     local FLOPPY_DEV_LIST="E2880 H1440 H720 D720 H360 D360 h1200 h720 h360 d360"
  4550.     local KERNTZ_LIST="UTCTIME LOCALTIME"
  4551.     local NIS_LIST="CLIENT SERVER"
  4552.     local PARALLEL_DEV_LIST="lp0 lp1 lp2"
  4553.     local USB_PRINTER_DEV_LIST="lp0 lp1 lp2"
  4554.     # all possibles gs devices
  4555.     # local PRINTER_LIST="apple bj10e bj200 lbp8 m8510 la50 la75 declj250 lj250 ln03 epson eps9high epsonc escp2 cdeskjet cdjcolor cdjmono deskjet djet500 djet500c cdj550 laserjet ljet2p ljet3 ljet4 ljetplus paintjet pj pjxl pjxl300 jetp3852 ibmpro necp6 oki ricoh sparc t4693d2 t4693d4 t4693d8 t4695"
  4556.     # available devices in gs 2.6.2
  4557.     # local PRINTER_LIST="bj10e bj200 cdeskjet cdjcolor cdjmono cdj550 djet500 djet500c ljet2p ljet3 ljet4 ljetplus paintjet epson escp2 necp6"
  4558.     # available devices in gs 3.33
  4559.     local PRINTER_LIST="NET PostScript bj200 bj10e lbp8 m8510 la50 la75 declj250 ln03 eps9high epsonc epson stcolor cdjcolor djet500 djet500c cdj500 cdeskjet cdj550 laserjet ljet2p ljet3 ljet4 ljetplus cdjmono pjxl300 pjtest paintjet pjxltest ibmpro necp6 sparc t4693d2 t4693d4 t4693d8"
  4560.     local PRINTER_PAPER="A3 A4 A5 Letter Legal Ledger"
  4561.     local PRINTER_RES="75x75 150x150 180x180 180x360 300x300 360x360 400x400 600x600 720x720 800x800"
  4562.     local SERIAL_DEV_LIST="ttyS0 ttyS1 ttyS2 ttyS3"
  4563.     local SERIAL_SPEED_LIST="115200 57600 38400 19200 9600 2400 1200"
  4564.     local SHELL_LIST="sh bash ash csh tcsh pdksh zsh"
  4565.     local TAPE_DEV_LIST="st0 st1 tpqic11 tpqic24 ftape tpqic120 tpqic150"
  4566.     local TERM_LIST="linux linux-mono vt100"
  4567.     local TIMEZONE_LIST="Australia/ACT Australia/Adelaide Australia/Brisbane Australia/Broken_Hill Australia/Canberra Australia/Darwin Australia/Hobart Australia/LHI Australia/Lindeman Australia/Lord_Howe Australia/Melbourne Australia/NSW Australia/North Australia/Perth Australia/Queensland Australia/South Australia/Sydney Australia/Tasmania Australia/Victoria Australia/West Australia/Yancowinna Brazil/Acre Brazil/DeNoronha Brazil/East Brazil/West CET Canada/Atlantic Canada/Central Canada/East-Saskatchewan Canada/Eastern Canada/Mountain Canada/Newfoundland Canada/Pacific Canada/Saskatchewan Canada/Yukon Chile/Continental Chile/EasterIsland Cuba EET Egypt Factory GB Eire GMT GMT+0 GMT+1 GMT+10 GMT+11 GMT+12 GMT+13 GMT+2 GMT+3 GMT+4 GMT+5 GMT+6 GMT+7 GMT+8 GMT+9 GMT-0 GMT-1 GMT-10 GMT-11 GMT-12 GMT-2 GMT-3 GMT-4 GMT-5 GMT-6 GMT-7 GMT-8 GMT-9 GMT0 GMT1 GMT10 GMT11 GMT12 GMT13 GMT2 GMT3 GMT4 GMT5 GMT6 GMT7 GMT8 GMT9 Greenwich Hongkong Iceland Iran Israel Jamaica Japan Libya MET Mexico/BajaNorte Mexico/BajaSur Mexico/General NZ Navajo PRC Poland ROC ROK Singapore SystemV/AST4 SystemV/AST4ADT SystemV/CST6 SystemV/CST6CDT SystemV/EST5 SystemV/EST5EDT SystemV/HST10 SystemV/MST7 SystemV/MST7MDT SystemV/PST8 SystemV/PST8PDT SystemV/YST9 SystemV/YST9YDT Turkey UCT US/Alaska US/Aleutian US/Arizona US/Central US/East-Indiana US/Eastern US/Hawaii US/Michigan US/Mountain US/Pacific US/Pacific-New US/Samoa UTC Universal W-SU WET Zulu"
  4568.     local X_SERVER_LIST
  4569.     local tag_prefix=
  4570.     local label_prefix=
  4571.     local items=
  4572.     local current=
  4573.     local show_type=raw
  4574.  
  4575.     if Is_SPARC ; then
  4576.         X_SERVER_LIST="Xsun Xsun24 XsunMono"
  4577.     else
  4578.         X_SERVER_LIST="XFree86 XF86_FBDev XF86_SVGA XF86_VGA16 XF86_3DLabs XF86_IBM8514 XF86_AGX  XF86_I128 XF86_Mach32 XF86_Mach64 XF86_Mach8 XF86_Mono XF86_P9000 XF86_S3 XF86_S3V XF86_W32 Xaccel Xmetro"
  4579.     fi
  4580.  
  4581.     if [ $# -gt 0 -a "$1" = "box" ]; then
  4582.         show_type=box
  4583.         shift 1
  4584.     fi
  4585.  
  4586.     if [ $# -eq 0 ]; then 
  4587.         Debug "no arg passed to List"
  4588.         Panic "List called without any arguments"
  4589.         return 1
  4590.     fi 
  4591.  
  4592.     case $1 in
  4593.     CD_DEV)    
  4594.         items="$CD_DEV_LIST"
  4595.         tag_prefix="/dev/"
  4596.         label_prefix="TYPE_CD_"
  4597.         ;;
  4598.     FLOPPY_DEV)
  4599.         items="$FLOPPY_DEV_LIST"
  4600.         tag_prefix="/dev/fd$2"
  4601.         label_prefix="TYPE_FLOPPY_"
  4602.         ;;
  4603.     KERNTZ)
  4604.         items="$KERNTZ_LIST"
  4605.         tag_prefix="KTZ_"
  4606.         label_prefix="TYPE_KERNTZ_"
  4607.         ;;
  4608.     NIS)
  4609.         items="$NIS_LIST"
  4610.         tag_prefix=""
  4611.         label_prefix="TYPE_NIS_"
  4612.         ;;
  4613.     PARALLEL_DEV)
  4614.         items="$PARALLEL_DEV_LIST"
  4615.         tag_prefix="/dev/"
  4616.         label_prefix="TYPE_PARALLEL_DEV_"
  4617.         ;;
  4618.     USB_PRINTER_DEV)
  4619.         items="$USB_PRINTER_DEV_LIST"
  4620.         tag_prefix="/dev/usb/"
  4621.         label_prefix="TYPE_USB_PRINTER_DEV_"
  4622.         ;;
  4623.     PRINTER)
  4624.         items="$PRINTER_LIST"
  4625.         label_prefix="TYPE_PRINTER_"
  4626.         ;;
  4627.     PRINTER_PAPER)
  4628.         items="$PRINTER_PAPER"
  4629.         label_prefix=""
  4630.         ;;
  4631.     PRINTER_RES)
  4632.         items="$PRINTER_RES"
  4633.         label_prefix=""
  4634.         ;;
  4635.     SERIAL_SPEED)
  4636.         items="$SERIAL_SPEED_LIST"
  4637.         label_prefix="TYPE_SPEED_B"
  4638.         ;;
  4639.     SERIAL_DEV)
  4640.         items="$SERIAL_DEV_LIST"
  4641.         tag_prefix="/dev/"
  4642.         label_prefix="TYPE_SERIAL_DEV_"
  4643.         ;;
  4644.     SHELL)
  4645.         items=""
  4646.         for current in $SHELL_LIST; do
  4647.             if [ -f $DIR_TARGET/bin/$current ]; then
  4648.                 items="$items $current"
  4649.             fi
  4650.         done
  4651.         tag_prefix="/bin/"
  4652.         label_prefix="TYPE_SHELL_"
  4653.         ;;
  4654.     TAPE_DEV)
  4655.         items="$TAPE_DEV_LIST"
  4656.         tag_prefix="/dev/"
  4657.         label_prefix="TYPE_TAPE_"
  4658.         ;;
  4659.     TERM)
  4660.         items="$TERM_LIST"
  4661.         label_prefix="TYPE_TERM_"
  4662.         ;;
  4663.     TIMEZONE)
  4664.         items="$TIMEZONE_LIST"
  4665.         label_prefix=""
  4666.         ;;
  4667.     X_SERVER)
  4668.         items=""
  4669.         for current in $X_SERVER_LIST; do
  4670.           if [  -f /usr/X11R6/bin/$current -o \
  4671.             -f $DIR_TARGET/usr/X11R6/bin/$current ]; then
  4672.                  items="$items $current"
  4673.           fi
  4674.         done
  4675.         label_prefix="TYPE_X_SERVER_"
  4676.         ;;
  4677.     *)
  4678.         Debug "fallback: calling from List old function <Build_$1>"
  4679.         Build_$1
  4680.         return 0
  4681.         ;;
  4682.     esac
  4683.     for current in $items ; do
  4684.         if [ "$show_type" = "raw" ]; then
  4685.             echo "${tag_prefix}${current} :${label_prefix}${current}:"
  4686.         elif [ "$show_type" = "box" ]; then
  4687.             if [ -n "$label_prefix" ]; then
  4688.                 # FIXME: special handling for PostScript
  4689.                 if [ "$current" = "PostScript" ];  then
  4690.                     echo "\"${tag_prefix}${current}\" \"Local PostScript Printer\" \\"
  4691.                 else
  4692.                     echo "\"${tag_prefix}${current}\" \":${label_prefix}${current}:\" \\"
  4693.                 fi
  4694.             else
  4695.                 echo "\"${tag_prefix}${current}\" \"${current}\" \\"
  4696.             fi
  4697.         else
  4698.             echo "unsupported show_type <$show_type>"
  4699.             return 1
  4700.         fi
  4701.     done
  4702.     return 0
  4703. }
  4704.  
  4705. Msg()
  4706. {
  4707.   FUNC_NAME=Msg
  4708.   echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  4709.   Box msg --text "$@" || return 1
  4710.   return 0
  4711. }
  4712.  
  4713. Msg2()
  4714. {
  4715.   FUNC_NAME=Msg2
  4716.   echo "$FUNC_NAME $@" >> $FILE_DEBUG_TRACE
  4717.   Box msg --var "$1" || return 1
  4718.   return 0
  4719. }
  4720.  
  4721. # libLSTdebug - Debug functions shared between several scripts
  4722. #
  4723. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  4724. #
  4725.  
  4726. Call_Direct()
  4727. {
  4728.     local cmd
  4729.     local retval
  4730.  
  4731.     echo
  4732.     echo -n "please enter name of function to call: "
  4733.     read cmd
  4734.     History "`date` Call_Direct: calling <$cmd>"
  4735.     $cmd
  4736.     retval=$?
  4737.     History "`date` Call_Direct: command <$cmd> returned with <$retval>"
  4738.     echo
  4739.     echo "command <$cmd> returned with <$retval>"
  4740. }
  4741.  
  4742. Debug()
  4743. {
  4744.     local screen=true
  4745.     local timestamp=true
  4746.     local command=
  4747.     local pipe=
  4748.     local disk_log=
  4749.     local permanent=$DIR_TARGET/var/adm/LST/log
  4750.  
  4751.     if [ "$MODE_DEBUG" != "true" ]; then
  4752.         return 0
  4753.     fi
  4754.     if [ -d $permanent ]; then
  4755.         disk_log=$permanent/debug
  4756.     fi
  4757.     if [ "X$1" = "X-d" -o "X$1" = "X--diskonly" ]; then
  4758.         screen=
  4759.         shift
  4760.     fi
  4761.     if [ "X$1" = "X-n" -o "X$1" = "X--nostamp" ]; then
  4762.         timestamp=
  4763.         shift
  4764.     fi
  4765.     if [ "X$1" = "X-D" -o "X$1" = "X--disk-nostamp" ]; then
  4766.         screen=
  4767.         timestamp=
  4768.         shift
  4769.     fi
  4770.     if [ "X$1" = "X-c" -o "X$1" = "X--command" ]; then
  4771.         screen=
  4772.         timestamp=
  4773.         shift
  4774.         command="$*"
  4775.     fi
  4776.     if [ "X$1" = "X-p" -o "X$1" = "X--pipe" ]; then
  4777.         timestamp=
  4778.         pipe=true
  4779.         shift
  4780.     fi
  4781.  
  4782.     if [ -n "$command" -a -n "$disk_log" ]; then
  4783.         $command >> $disk_log 2>&1
  4784.         return 0
  4785.     fi
  4786.     if [ -n "$pipe" ]; then
  4787.         if [ -n "$disk_log" ]; then
  4788.             tee -a $disk_log >> $FILE_TMP_DEBUG
  4789.         else
  4790.             cat - >> $FILE_TMP_DEBUG
  4791.         fi
  4792.         return 0
  4793.     fi
  4794.     if [ -n "$screen" ]; then
  4795.         echo "`date` debug: $@" >> $FILE_TMP_DEBUG
  4796.     fi
  4797.     if [ -z "$disk_log" ]; then
  4798.         return 0
  4799.     fi
  4800.     if [ -n "$timestamp" ]; then
  4801.         echo "`date` debug: $@" >> $disk_log
  4802.     else
  4803.         echo "$@" >> $disk_log
  4804.     fi
  4805. }
  4806.  
  4807. Log_Cmd()
  4808. {
  4809.     local num
  4810.  
  4811.     if [ -f /tmp/.log ]; then
  4812.         num="`cat /tmp/.log`"
  4813.         if [ -z "$num" ]; then
  4814.             num=0
  4815.         fi
  4816.         num="`do_calc $num + 1`"
  4817.         echo "$num" > /tmp/.log
  4818.         cp -a $FILE_TMP_COMMAND /var/adm/LST/log/cmd.$num
  4819.         echo "debug: cmd $num saved to /var/adm/LST/log/cmd.$num" > /dev/tty5
  4820.         echo "debug: calling cmd $num:" > /dev/tty5
  4821.     fi
  4822. }
  4823.  
  4824. Debug_Stop()
  4825. {
  4826.     local debug_ans
  4827.     echo "Debug_Stop called. Press <Enter> to continue."
  4828.     read debug_ans
  4829. }
  4830.  
  4831. # Do_Log ( [-d] [-n] [-f FILE] text_to_log )
  4832. #
  4833. # Log a string for logging or postponed display
  4834. # Should be usable instead of echo.
  4835. #
  4836. # Options:
  4837. # -d        delete file
  4838. # -n        do not append newline
  4839. # -f FILE    log to file FILE
  4840. #
  4841. Do_Log()
  4842. {
  4843.     local deleteflag=
  4844.     local appendflag=
  4845.     local logfile=$FILE_TMP_LOG
  4846.  
  4847.     # parse loop
  4848.     while [ 1 ]; do
  4849.         if [ $# -gt 1 -a "X$1" = 'X-f' ]; then
  4850.                 logfile=$2
  4851.                 shift 2
  4852.         elif [ $# -gt 0 ]; then
  4853.             if [ "X$1" = 'X-d' ]; then
  4854.                 deleteflag=true
  4855.                 shift 1
  4856.             elif [ "X$1" = 'X-n' ]; then
  4857.                 appendflag=true
  4858.                 shift 1
  4859.             else
  4860.                 # no more options, so the rest is message
  4861.                 break
  4862.             fi
  4863.         fi
  4864.     done
  4865.     Debug --nostamp "$@"
  4866.     if [ -n "$deleteflag" ]; then
  4867.         rm -f "$logfile"
  4868.     fi
  4869.     if [ -n "$appendflag" ]; then
  4870.         echo -n "$@" >> $logfile
  4871.     else
  4872.         echo "$@" >> $logfile
  4873.     fi
  4874. }
  4875.  
  4876. Disable_Auto_Mode()
  4877. {
  4878.     CMD_BOX="box"
  4879.     set_val -f /etc/lst.cnf CMD_BOX "box"
  4880.     MODE_QUERY="prompt"
  4881.     set_val MODE_QUERY prompt
  4882.     MODE_SPEED="normal"
  4883.     set_val MODE_SPEED normal
  4884.     return 0
  4885. }
  4886.  
  4887. Error()
  4888. {
  4889.     local error_help=
  4890.     local error_text=
  4891.     local error_file=
  4892.  
  4893.     echo -n ""
  4894.     # swvc 1
  4895.     if [ $# -gt 1 -a "$1" = '--file' ]; then
  4896.         error_file="$2"
  4897.         shift 2
  4898.     fi
  4899.     if [ $# -gt 1 -a "$1" = '--help' ]; then
  4900.         error_help="$2"
  4901.         shift 2
  4902.     else
  4903.         error_help=":HELP_ERROR:"
  4904.     fi
  4905.     if [ $# -gt 0 ]; then
  4906.         error_text=":ERR_MSG_WAS: ; ; $@ ; "
  4907.     else
  4908.         error_text=":ERR_IS_UNKNOWN:"
  4909.     fi
  4910.  
  4911.     History "`date` error: $error_text"
  4912.     if [ -z "$error_file" ]; then
  4913.         $CMD_BOX --title ":ERROR:" --help "$error_help" --msg "$error_text"
  4914.     else
  4915.         if [ -s $error_file ]; then
  4916.             History "error log in $error_file:"
  4917.             History "`cat $error_file`"
  4918.             $CMD_BOX --title ":ERROR:" --help "$error_help" --text "$error_text" --browse $error_file
  4919.             rm -f $error_file
  4920.         else
  4921.             $CMD_BOX --title ":ERROR:" --help "$error_help" --msg "$error_text"
  4922.         fi
  4923.     fi
  4924.     Disable_Auto_Mode
  4925.     return 0
  4926. }
  4927.  
  4928. Error2()
  4929. {
  4930.     echo -n ""
  4931.     # swvc 1
  4932.     echo "--------------------------------" >> $FILE_TMP_ERR
  4933.     History "`date` error: $@"
  4934.     History "`cat $FILE_TMP_ERR`"
  4935.     Disable_Auto_Mode
  4936.     Box err --var "$1" $FILE_TMP_ERR || return 1
  4937.     return 0
  4938. }
  4939.  
  4940. Err_Not_Available()
  4941. {
  4942.     Error --help ":HELP_NOT_AVAILABLE:" ":INFO_NOT_AVAILABLE:"
  4943. }
  4944.  
  4945. Err_Not_Implemented()
  4946. {
  4947.     Error --help ":HELP_NOT_IMPLEMENTED:" ":INFO_NOT_IMPLEMENTED:"
  4948. }
  4949.  
  4950. History()
  4951. {
  4952.     Do_Log -f $FILE_LOG_HISTORY "$@"
  4953. }
  4954.  
  4955. History_Install()
  4956. {
  4957.     History "`date` $LOGNAME: $PKG_NAME: $@"
  4958. }
  4959.  
  4960. Panic()
  4961. {
  4962.     History "`date` panic: $@"
  4963.     echo
  4964.     echo "Panic!"
  4965.     echo "$@"
  4966.     echo
  4967.     while [ 1 ]; do
  4968.         echo -n "abort (a), continue (c), show var (v), set var (s), call function (f): "
  4969.         read ans
  4970.         if [ "$ans" = "a" ]; then
  4971.             History "`date` panic: abort and exit."
  4972.             reset
  4973.             exit 1
  4974.         elif [ "$ans" = "v" ]; then
  4975.             History "`date` panic: continue with Show_Value."
  4976.             Show_Value
  4977.         elif [ "$ans" = "s" ]; then
  4978.             History "`date` panic: continue with Set_Value."
  4979.             Set_Value
  4980.         elif [ "$ans" = "f" ]; then
  4981.             History "`date` panic: continue with Call_Direct."
  4982.             Call_Direct
  4983.         elif [ "$ans" = "c" ]; then
  4984.             History "`date` panic: try to continue."
  4985.             return 0
  4986.         fi
  4987.     done
  4988. }
  4989.  
  4990. Set_Value()
  4991. {
  4992.     local var
  4993.     local value
  4994.  
  4995.     echo -n "enter name of variable to set: "
  4996.     read var
  4997.     echo -n "enter value of $var: "
  4998.     read value
  4999.     echo "export $var=\"$value\"" > /tmp/val
  5000.     . /tmp/val
  5001.     History "`date` Set_Value: value of <$var> set to <$value>"
  5002.     rm -f /tmp/val
  5003. }
  5004.  
  5005. Show_Value()
  5006. {
  5007.     local var
  5008.  
  5009.     echo -n "enter name of variable to show: "
  5010.     read var
  5011.     eval "echo \"\$$var\"" > /tmp/val
  5012.     echo "$var=<`cat /tmp/val`>"
  5013.     History "`date` Show_Value: value of <$var> is <`cat /tmp/val`>"
  5014.     rm -f /tmp/val
  5015. }
  5016.  
  5017. Simulate()
  5018. {
  5019.   $CMD_BOX --help ":MENU_SIMULATE_HELP:" --title ":MENU_SIMULATE_TITLE:" --msg ":MENU_SIMULATE_TEXT: ; ; $*" 2> /dev/null
  5020. }
  5021.  
  5022. Warn()
  5023. {
  5024.     local warn_help=
  5025.     local warn_text=
  5026.     local warn_file=
  5027.  
  5028.     if [ $# -gt 1 -a "$1" = '--file' ]; then
  5029.         warn_file="$2"
  5030.         shift 2
  5031.     fi
  5032.     if [ $# -gt 1 -a "$1" = '--help' ]; then
  5033.         warn_help="$2"
  5034.         shift 2
  5035.     else
  5036.         warn_help=":HELP_WARNING:"
  5037.     fi
  5038.     if [ $# -gt 0 ]; then
  5039.         warn_text=":WARNING: ! ; ; $@ ; "
  5040.     else
  5041.         warn_text=":WARNING: !"
  5042.     fi
  5043.  
  5044.     History "`date` warn: $warn_text"
  5045.     if [ -z "$warn_file" ]; then
  5046.         $CMD_BOX --title ":WARNING:" --help "$warn_help" --msg "$warn_text" || return 1
  5047.     else
  5048.         if [ -f $warn_file ]; then
  5049.             echo "--------------------------" >> $warn_file
  5050.             History "error log in $warn_file:"
  5051.             History "`cat $warn_file`"
  5052.             $CMD_BOX --title ":WARNING:" --help "$warn_help" --text "$warn_text" --browse $warn_file || return 1
  5053.             rm -f $warn_file
  5054.         else
  5055.             $CMD_BOX --title ":WARNING:" --help "$warn_help" --msg "$warn_text" || return 1
  5056.         fi
  5057.     fi
  5058.     return 0
  5059. }
  5060.  
  5061. Warn2()
  5062. {
  5063.     History "`date` warn: $1"
  5064.     Box warn --var "$1" || return 1
  5065.     return 0
  5066. }
  5067.  
  5068. # libLSTanalyse
  5069.  
  5070. Write_Analyse_Infos()
  5071. {
  5072.   local was_mounted=
  5073.   local extension=0
  5074.   local rfile=
  5075.   local i
  5076.  
  5077.   mount | fgrep 'on /floppy' > /dev/null && was_mounted=true
  5078.   umount /floppy >/dev/null 2>&1
  5079.   Msg ":DO_INSERT_DOS_FLOPPY:" || return 0
  5080.   mount -t msdos /dev/fd0H1440 /floppy
  5081.   if [ $? -ne 0 ]; then
  5082.     Msg ":ERR_MOUNT_FLOPPY_FAILED:"
  5083.   else
  5084.     Info ":INFO_ANALYSE_RUNNING:"
  5085.     while [ 1 ]; do
  5086.       if [ ! -f /floppy/analyse.$extension ]; then
  5087.     break
  5088.       else
  5089.     extension="`do_calc $extension + 1`"
  5090.       fi
  5091.     done
  5092.     rfile="/floppy/analyse.$extension"
  5093.     echo "=== report from `sysinfo --version` ===" > $rfile
  5094.     sysinfo >> $rfile
  5095.     for i in /proc/interrupts /proc/ioports /proc/dma /proc/pci /proc/cpuinfo /proc/modules /proc/devices /proc/net/dev /var/adm/LST/analyse/boot.params /var/adm/LST/analyse/boot.msg ; do
  5096.       if [ -f $i ]; then
  5097.     echo "=== $i ===" >> $rfile
  5098.     cat $i >> $rfile
  5099.       fi
  5100.     done
  5101.     echo "=== current dmesg output at `date` ===" >> $rfile
  5102.     dmesg >> $rfile
  5103.  
  5104.     if [ $? -ne 0 ]; then
  5105.       Msg ":ERR_WRITE_FAILED:"
  5106.     else
  5107.       sync
  5108.       sync
  5109.       umount /floppy >/dev/null 2>&1
  5110.       Msg "analyse.$extension ; :INFO_WRITE_SUCCEEDED:"
  5111.     fi
  5112.   fi
  5113.   while [ 1 ]; do
  5114.     umount /floppy >/dev/null 2>&1
  5115.     if [ -z "$was_mounted" ]; then return 0 ; fi
  5116.     Msg ":DO_INSERT_MODULES_FLOPPY:" || return 1
  5117.     mount -r /dev/fd0H1440 /floppy && break
  5118.     Msg ":ERR_MOUNT_FLOPPY_FAILED:" || return 1
  5119.   done
  5120.   return 0
  5121. }
  5122.  
  5123. Show_LST_Config()
  5124. {
  5125.     $CMD_BOX --title "$FILE_LST_CONF" --text ":SHOW_LST_CONFIG_TEXT:" --browse $FILE_LST_CONF
  5126. }
  5127.  
  5128. Show_System_Config()
  5129. {
  5130.     $CMD_BOX --title "$FILE_SYSTEM_CONF" --text ":SHOW_SYSTEM_CONFIG_TEXT:" --browse $FILE_SYSTEM_CONF
  5131. }
  5132.  
  5133. Show_Boot_Msg()
  5134. {
  5135.   dmesg > $FILE_BOOT_MSG
  5136.   if [ -f $FILE_BOOT_MSG ]; then
  5137.     $CMD_BOX --title "$FILE_BOOT_MSG" --text ":SHOW_BOOT_MSG_TEXT:" --browse $FILE_BOOT_MSG
  5138.   else
  5139.     Error "$FILE_BOOT_MSG ; :ERR_FILE_NOT_FOUND:"
  5140.   fi
  5141. }
  5142.  
  5143.  
  5144. # libLSTdisk - disk handling library shared between several scripts
  5145. #
  5146. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  5147. #
  5148.  
  5149. # List_PARTITION ( [TYPE] )
  5150. #
  5151. # TYPE may be DOS, Linux, Swap, Swapfile, HPFS, Bootmanager, Src, Dest,
  5152. #      the name of a partition or omitted (all partitions)
  5153. # outputs lines in raw format
  5154. #
  5155. List_PARTITION()
  5156. {
  5157.   if [ $# -eq 0 ]; then
  5158.     sysinfo --box --partition
  5159.   else
  5160.     case $1 in
  5161.     DOS|Linux|Dest|Src|HPFS|Swap|Swapfile|Bootmanager)
  5162.       sysinfo --box -C $1 --partition
  5163.       ;;
  5164.     DestSorted)
  5165.       sysinfo --box -C Linux --partition
  5166.       sysinfo --box -C DOS --partition
  5167.       ;;
  5168.     *)
  5169.       sysinfo --box -P $1 --partition
  5170.       ;;
  5171.     esac
  5172.   fi
  5173. }
  5174.  
  5175. # Build_PARTITION ( [--exclude FILE] [TYPE] )
  5176. #
  5177. # TYPE may be DOS, Linux, Swap, Swapfile, HPFS, Bootmanager, Src, Dest,
  5178. #      the name of a partition or omitted (all partitions)
  5179. # outputs lines in menu-item format and adds extra input possibility
  5180. #
  5181. Build_PARTITION()
  5182. {
  5183.   local exclude_file=
  5184.  
  5185.   if [ $# -gt 1 -a "$1" = '--exclude' ]; then
  5186.     exclude_file="$2"
  5187.     shift 2
  5188.   fi
  5189.  
  5190.   Debug "Building partition-list with argument <$1>"
  5191.   if [ -n "$exclude_file" -a -s "$exclude_file" ]; then
  5192.     Debug "Respecting exclude file $exclude_file:"
  5193.     Debug -c cat $exclude_file
  5194.     sed 's/$/ /' $exclude_file > $exclude_file.tmp
  5195.     List_PARTITION $1 | fgrep -vf $exclude_file.tmp
  5196.     rm -f $exclude_file.tmp
  5197.   else
  5198.     Debug "No or empty exclude file specified"
  5199.     List_PARTITION $1
  5200.   fi
  5201.   Is_Expert && echo "\"other\" \":DEVICE_DIRECT:\" \\" 
  5202.   return 0
  5203. }
  5204.  
  5205. Build_HARDDISK_DEV()
  5206. {
  5207.   sysinfo --box --disk
  5208. }
  5209.  
  5210. Build_Fstab_Menu()
  5211. {
  5212.   do_quote -f $FILE_ETC_FSTAB | sed 's/    / /g' >> $FILE_TMP_COMMAND
  5213.   echo "2> $FILE_TMP_ANSWER" >> $FILE_TMP_COMMAND
  5214.   chmod 755 $FILE_TMP_COMMAND
  5215. }
  5216.  
  5217. Menu_Config_Swap()
  5218. {
  5219.   local swapdir=/swap
  5220.   local swapfile=swapfile
  5221.   local swapdev=
  5222.   local swaptype=swap
  5223.   local swapsize=
  5224.   local partid=
  5225.   local defval=
  5226.  
  5227.   defval="`get_val CONF_PARTITIONS_SWAP | cut -d' ' -f 1`"
  5228.   if [ -z "$defval" ]; then
  5229.       defval="`sysinfo --tag -C Swap --partition | sed -n '1p'`"
  5230.   fi
  5231.  
  5232.   while [ 1 ]; do
  5233.     # FIXME: enable swapfile-option
  5234.     Choose --none --menutitle ":CHOOSE_PARTITION_SWAP_MENUTITLE:" --build "Build_PARTITION Swap" SWAP $defval || return 1
  5235.     swapdev="$ANSWER"
  5236.     if [ -z "$ANSWER" ]; then return 0 ; fi
  5237.     partid="`Get_Partition_Info --id $swapdev`"
  5238.     case $partid in
  5239.     1|4|6|11|12|14)
  5240.     swaptype=umsdos
  5241.     ;;
  5242.     130)
  5243.     swaptype=swap
  5244.     swapsize="`Get_Partition_Info --size $swapdev`"
  5245.     ;;
  5246.     131)
  5247.     swaptype=ext2
  5248.     ;;
  5249.     esac
  5250.     case $swaptype in 
  5251.     swap)
  5252.     swapoff $swapdev > /dev/null 2>&1
  5253.     Info ":INFO_SWAP_INITIALIZING:"
  5254.     mkswap -c $swapdev $swapsize | Debug -p || continue
  5255.     Info ":INFO_SWAP_ACTIVATING:"
  5256.     sync
  5257.     sync
  5258.     sync
  5259.     sync
  5260.     sleep 3
  5261.     swapon $swapdev || continue
  5262.     if [ -d $DIR_TARGET/etc ]; then
  5263.       echo "$swapdev    none    swap defaults 0 0" >> $DIR_TARGET/$FILE_ETC_FSTAB
  5264.     else
  5265.       echo "$swapdev" > $FILE_SWAP_SEL
  5266.     fi
  5267.     return 0
  5268.     ;;
  5269.     umsdos|ext2)
  5270.     mkdir -p $swapdir
  5271.     Do_Mount -t $swaptype $swapdev $swapdir || continue
  5272.     if [ "$swaptype" = "umsdos" ]; then
  5273.       mkdir -p $swapdir/linux
  5274.       swapfile=linux/swapfile
  5275.     fi
  5276.     if [ -f $swapdir/$swapfile ]; then
  5277.       swapsize="`filesize $swapdir/$swapfile`"
  5278.       swapsize="`do_calc $swapsize / 1024`"
  5279.       dummy=":PARTITION: $swapdev ; :FILE: $swapfile ; :SIZE: ${swapsize}kB ; "
  5280.       Ask_Bool --pretext "$dummy" SWAP_FILE j || continue
  5281.       if [ "$ANSWER" = "1" ]; then
  5282.         rm -f $swapdir/$swapfile
  5283.       fi
  5284.     fi
  5285.     if [ ! -f $swapdir/$swapfile ]; then
  5286.       swapsize="`df /swap | fgrep $swapdev | cut -c 37-45`"
  5287.       if [ $swapsize -gt 8192 ]; then
  5288.         swapsize=8192
  5289.       elif [ $swapsize -gt 4096 ]; then
  5290.         swapsize=4096
  5291.       else
  5292.         Msg ":WARN_NO_SPACE_FOR_SWAPFILE:"
  5293.         continue
  5294.       fi
  5295.     fi
  5296.     ;;
  5297.     esac
  5298.     Info ":INFO_SWAP_INITIALIZING:"
  5299.     if [ ! -f $swapdir/$swapfile ]; then
  5300.     dd if=/dev/zero of=$swapdir/$swapfile bs=1k count=$swapsize || continue
  5301.     sync
  5302.     fi
  5303.     mkswap $swapdir/$swapfile $swapsize || continue
  5304.     Info ":INFO_SWAP_ACTIVATING:"
  5305.     sync
  5306.     sync
  5307.     sync
  5308.     sync
  5309.     sleep 3
  5310.     swapon $swapdir/$swapfile || continue
  5311.     if [ -d $DIR_TARGET/etc ]; then
  5312.       echo "$swapdir/$swapfile    none    swap defaults 0 0" >> $DIR_TARGET/$FILE_ETC_FSTAB
  5313.     fi
  5314.     # do we have less than 12 MB and no swap enabled?
  5315.     if [ `filesize /proc/kcore` -lt 12582912 -a \
  5316.     "`sysinfo --swap --var 2>&1 >/dev/null | cut -d':' -f 2`" -eq 0 ]; then
  5317.     echo "NOT_ENOUGH_RAM" >> $FILE_TMP_ERR
  5318.     Error2 NOT_ENOUGH_RAM
  5319.     # do not let them proceed as it won't work anyway
  5320.     continue
  5321.     fi
  5322.     return 0
  5323.   done
  5324. }
  5325.  
  5326. # test harddisk geometry
  5327. #
  5328. Check_Disk_Geometry()
  5329. {
  5330.     local f_name=Check_Disk_Geometry
  5331.     local f_args=1 # (hardisk) ->
  5332.     local harddisk=
  5333.     local diskname=
  5334.     local geometry=
  5335.     local cylinders=
  5336.     local heads=
  5337.     local sectors=
  5338.     local warning=
  5339.  
  5340.     Check_Args $f_name $f_args $# "$@" || return 255
  5341.     harddisk=$1
  5342.     diskname="`echo $harddisk | sed 's/^\/dev\///'`"
  5343.     geometry="`Get_Val CONF_DISK_GEO_$diskname`" 2> /dev/null
  5344.     if [ -z "$geometry" ]; then
  5345.         geometry="`sysinfo --var --disk $harddisk 2>&1 >/dev/null | cut -d: -f 3,4,5 `"
  5346.         IFS=':' read cylinders heads sectors << EOF
  5347. $geometry
  5348. EOF
  5349.     else
  5350.         read cylinders heads sectors << EOF
  5351. $geometry
  5352. EOF
  5353.     fi
  5354.  
  5355.     # check for invalid number of cylinders and warn if > 1024
  5356.     if [ -z "$cylinders" -o $cylinders -le 0 ]; then
  5357.         warning=INVALID_GEOMETRY
  5358.     else
  5359.         if [ $cylinders -gt 1024 ]; then
  5360.             warning=MANY_CYLINDERS
  5361.         fi
  5362.     fi
  5363.  
  5364.     # check for invalid number of heads
  5365.     if [ -z "$heads" -o $heads -gt 255 -o $heads -le 0 ]; then
  5366.         warning=INVALID_GEOMETRY
  5367.     fi
  5368.  
  5369.     # check for invalid number of sectors
  5370.     if [ -z "$sectors" -o $sectors -gt 63 -o $sectors -le 0 ]; then
  5371.         warning=INVALID_GEOMETRY
  5372.     fi
  5373.     if [ -n "$warning" ]; then
  5374.         Warn2 $warning
  5375.         return 1
  5376.     fi
  5377.     return 0
  5378. }
  5379.  
  5380. Check_Mount_Partition()
  5381. {
  5382.     local f_name=Check_Mount_Partition
  5383.     local f_args=1 # (partition) -> ERROR, STATUS
  5384.     local busydir=
  5385.  
  5386.     Check_Args $f_name $f_args $# "$@" || return 255
  5387.     Check_Partition_Valid $1 || return 1
  5388.     mount | cut -d' ' -f 1 | fgrep -x "$1" > /dev/null 2>&1 
  5389.     if [ $? -ne 0 ]; then
  5390.         ERROR="$1 ; :ERR_PARTITION_NOT_MOUNTED:"
  5391.         return 1 
  5392.     else
  5393.         busydir="`mount | fgrep "$1 on" | cut -d' ' -f 3`"
  5394.         if [ -n "$busydir" ]; then
  5395.             busydir="(${busydir})"
  5396.         fi
  5397.         STATUS="$1 $busydir ; :ERR_PARTITION_ALREADY_MOUNTED:"
  5398.         return 0
  5399.     fi
  5400. }
  5401.  
  5402. Check_Directory()
  5403. {
  5404.     local f_name=Check_Directory
  5405.     local f_args=1 # (directory) -> ERROR
  5406.  
  5407.     Check_Args $f_name $f_args $# "$@" || return 255
  5408.     if [ -d $1 ]; then
  5409.         return 0
  5410.     else
  5411.         ERROR="$1 ; :ERR_DIRECTORY_INVALID:"
  5412.         return 1
  5413.     fi
  5414. }
  5415.  
  5416. # checks if directory is mountable and if false sets STATUS to device
  5417. # and ERROR to an error message
  5418. #
  5419. Check_Directory_Busy()
  5420. {
  5421.     local f_name=Check_Directory_Busy
  5422.     local f_args=1 # (directory) -> STATUS, ERROR
  5423.     export STATUS=
  5424.     export ERROR=
  5425.  
  5426.     Check_Args $f_name $f_args $# "$@" || return 255
  5427.     Check_Directory $1 || return 1
  5428.     mount | cut -d' ' -f 3 | fgrep -x "$1" > /dev/null 2>&1 
  5429.     if [ $? -eq 0 ]; then
  5430.         STATUS="`mount | fgrep "on $1" | cut -d' ' -f 1`"
  5431.         Debug "directory $1 is busy because $STATUS is mounted"
  5432.         ERROR="$1 ; :ERR_DIRECTORY_BUSY:"
  5433.         return  0
  5434.     fi
  5435.     Debug "directory $1 is not busy"
  5436.     return 1
  5437. }
  5438.  
  5439. # checks if a device is already mounted and if true sets STATUS to directory
  5440. # and ERROR to an error message
  5441. #
  5442. Check_Device_Mounted()
  5443. {
  5444.     local f_name=Check_Device_Mounted
  5445.     local f_args=1 # (device) -> STATUS, ERROR
  5446.     export STATUS=
  5447.     export ERROR=
  5448.  
  5449.     Check_Args $f_name $f_args $# "$@" || return 255
  5450.     # FIXME handle devices too (as NFS-Paths), not only partitions
  5451.     mount | cut -d' ' -f 1 | fgrep -x "$1" >/dev/null 2>&1 
  5452.     if [ $? -eq 0 ]; then
  5453.         STATUS="`mount | fgrep "$1 on" | cut -d' ' -f 3`"
  5454.         Debug "device $1 is already mounted on $STATUS"
  5455.         ERROR="$1 ; :ERR_PARTITION_ALREADY_MOUNTED:"
  5456.         return 0
  5457.     fi
  5458.     Debug "device $1 is not mounted"
  5459.     return 1
  5460. }
  5461.  
  5462. # checks if a partition is a primary partition and if false sets
  5463. # ERROR to an error message
  5464. #
  5465. Check_Partiton_Primary()
  5466. {
  5467.     local f_name=Check_Partition_Primary
  5468.     local f_args=1 # (partition) -> ERROR
  5469.     export ERROR=
  5470.  
  5471.     Check_Args $f_name $f_args $# "$@" || return 255
  5472.     Check_Partition_Valid $1 || return 1
  5473.     if [ `echo $1 | cut -c 9-` -lt 5 ]; then
  5474.         if [ `Get_Partition_Info --id $1` -ne 5 ]; then
  5475.             return 0
  5476.         fi
  5477.     fi
  5478.     ERROR="$1 ; :ERR_NO_PRIMARY_PARTITION:"
  5479.     return 1
  5480. }
  5481.  
  5482. # checks if a partition is valid and if false sets ERROR to an error message
  5483. #
  5484. Check_Partition_Valid()
  5485. {
  5486.     local f_name=Check_Partition_Valid
  5487.     local f_args=1 # (partition) -> ERROR
  5488.     export ERROR=
  5489.  
  5490.     # Debug "Check_Partition_Valid: $@"
  5491.     Check_Args $f_name $f_args $# "$@" || return 255
  5492.     if [ ! -b $1 ]; then
  5493.         ERROR="$1 ; :ERR_INVALID_BLOCK_DEVICE:"
  5494.         return 1
  5495.     fi
  5496.     dummy="`sysinfo -P $1 --partition --var 2>&1 >/dev/null`"
  5497.     if [ -z "$dummy" ]; then
  5498.         ERROR="$1 ; :ERR_PARTITION_NOT_FOUND:"
  5499.         return 1
  5500.     fi
  5501.     return 0
  5502. }
  5503.  
  5504. # Smart mount frontend
  5505. #
  5506. # returns:
  5507. # 0    ok
  5508. # 1    was already mounted
  5509. # 2    could not be mounted 
  5510. # 255    parameter error 
  5511. #
  5512. Do_Mount()
  5513. {
  5514.     local f_name=Do_Mount
  5515.     local f_args=2 # ([--verbose] [--types TYPES] [-t TYPE] [-o OPTIONS]
  5516.             # DEVICE DIRECTORY) -> ERROR
  5517.     local verbose_mode=
  5518.     local mounttype=
  5519.     local mountopt=
  5520.     local mountdev=
  5521.     local mountdir=
  5522.     local mountline=
  5523.     local partid=
  5524.     local dummy=
  5525.     local loop=
  5526.     local mounttypealt="ext2 umsdos msdos minix iso9660 hpfs"
  5527.     export ANSWER=
  5528.  
  5529.     # parse options
  5530.     while [ 1 ]; do
  5531.         if [ $# -gt 1 ]; then
  5532.             case $1 in
  5533.             --types)
  5534.                 mounttypealt="$2"
  5535.                 shift 2
  5536.                 continue;;
  5537.             -t)
  5538.                 mounttype="$2"
  5539.                 mounttypealt=""
  5540.                 shift 2
  5541.                 continue;;
  5542.             -o)
  5543.                 mountopt="$2"
  5544.                 shift 2
  5545.                 continue;;
  5546.             esac
  5547.         fi
  5548.         if [ $# -gt 0 ]; then
  5549.             case $1 in
  5550.             --verbose)
  5551.                 verbose_mode=true
  5552.                 shift 1
  5553.                 continue;;
  5554.             esac
  5555.         fi
  5556.         Check_Args $f_name $f_args $# "$@" || return 255
  5557.         mountdev=$1
  5558.         mountdir=$2
  5559.         shift 2
  5560.         break
  5561.     done
  5562.  
  5563.     if [ -z "$mounttype" ]; then
  5564.         # try to determine mounttype
  5565.         # check for nfs mount
  5566.         if [ -n "`echo $mountdev | sed -n '/:/p'`" ]; then
  5567.             mounttype=nfs
  5568.             mounttypealt=
  5569.             # shift 1 
  5570.         # check for device mount
  5571.         elif [ -n "`echo $mountdev | sed -n '/^\/dev\//p'`" ]; then
  5572.             # check for iso9660 mount (dirty hack)
  5573.             if [ -n "`echo $mountdev | sed -n '/cd/p'`" ]; then
  5574.                 mounttype=iso9660
  5575.                 mountopt="ro"
  5576.             # check for floppy mount (dirty hack)
  5577.             elif [ -n "`echo $mountdev | sed -n '/^\/dev\/fd/p'`" ]; then
  5578.                 mounttype=msdos
  5579.                 mounttypealt="minix umsdos"
  5580.             # check for partition mount (dirty hack)
  5581.             elif [ -n "`echo $mountdev | sed -n '/^\/dev\/[irshx]d/p'`" ]; then
  5582.                 # Get partition id
  5583.                 partid="`Get_Partition_Info --id $mountdev`"
  5584.                 if [ -z "$partid" ]; then
  5585.                     Error "partition-id of $mountdev could not be determined!"
  5586.                     return 1
  5587.                 fi
  5588.                 case $partid in
  5589.                 1|4|6|11|12|14)
  5590.                     mounttype="msdos"
  5591.                     mounttypealt="umsdos"
  5592.                     ;;
  5593.                 7)
  5594.                     mounttype="hpfs"
  5595.                     mounttypealt="msdos umsdos"
  5596.                     ;;
  5597.                 128|129)
  5598.                     mounttype="minix"
  5599.                     mounttypealt="ext2"
  5600.                     ;;
  5601.                 130)
  5602.                     mounttype="swap"
  5603.                     ;;
  5604.                 131)
  5605.                     mounttype="ext2"
  5606.                     mounttypealt="minix ext xiafs"
  5607.                     ;;
  5608.                 *)
  5609.                     Error "unknown partition-id $partid for $mountdev!"
  5610.                     return 2
  5611.                     ;;
  5612.                 esac
  5613.             fi # no partition
  5614.         fi # no device
  5615.     fi # mounttype=""
  5616.  
  5617.     # mount loop
  5618.     rm -f $FILE_TMP_ERR
  5619.     for loop in $mounttype $mounttypealt ; do
  5620.         Do_Load_Driver filesystem $mounttype || continue
  5621.         Check_Device_Mounted $mountdev
  5622.         if [ $? -eq 0 ]; then
  5623.             if [ "$STATUS" = "$mountdir" ]; then
  5624.                 Debug "keep it mounted. Ok"
  5625.                 mount | fgrep "$mountdev on" | cut -d' ' -f 5 > $FILE_TMP_VAL
  5626.                 ANSWER="`cat $FILE_TMP_VAL`"
  5627.                 return 0
  5628.             else
  5629.                 Debug "unmount it."
  5630.                 Do_Umount $mountdev
  5631.             fi
  5632.         fi
  5633.         Check_Directory_Busy $mountdir
  5634.         if [ $? -eq 0 ]; then
  5635.             if [ "$STATUS" = "$mountdev" ]; then
  5636.                 Debug "keep it mounted. Ok"
  5637.                 mount | fgrep "$mountdev on" | cut -d' ' -f 5 > $FILE_TMP_VAL
  5638.                 ANSWER="`cat $FILE_TMP_VAL`"
  5639.                 return 0
  5640.             else
  5641.                 Debug "unmount it."
  5642.                 Do_Umount $mountdir
  5643.             fi
  5644.         fi
  5645.         dummy=
  5646.         if [ -n "$mountopt" ]; then
  5647.             dummy="-o $mountopt"
  5648.         fi
  5649.         rm -f /etc/mtab~
  5650.         if [ "$loop" = "nfs" ]; then
  5651.             Info ":INFO_TRYING_NFS_MOUNT:"
  5652.         fi
  5653.         Debug "Trying mount -t $loop $dummy $mountdev $mountdir"
  5654.         # Do_Clear_Screen
  5655.         # echo "trying: mount -t $loop $dummy $mountdev $mountdir"
  5656.         mount -t $loop $dummy $mountdev $mountdir > $FILE_TMP_ERR.tmp 2>&1
  5657.         retval=$?
  5658.         if [ $retval -eq 0 ]; then
  5659.             # Success
  5660.             Debug "Success!"
  5661.             # if [ -n "$verbose_mode" ]; then
  5662.                 # Info ":PARTITION: = $mountdev ; :DIRECTORY: = $mountdir ; :FILESYTEM_TYPE: = $mounttype ; :INFO_MOUNT_SUCCESS:"
  5663.                 # sleep 1
  5664.             # fi
  5665.             ANSWER="$loop"
  5666.             return 0
  5667.         else
  5668.             # Failure
  5669.             Debug "Failed!"
  5670.             Debug -c cat $FILE_TMP_ERR.tmp
  5671.             cat $FILE_TMP_ERR.tmp >> $FILE_TMP_ERR
  5672.         fi
  5673.     done
  5674.     # if [ -n "$verbose_mode" ]; then
  5675.         Error2 MOUNT_FAILED
  5676.     # fi
  5677.     return 2
  5678. }
  5679.  
  5680. Do_Umount()
  5681. {
  5682.     local f_name=Do_Umount
  5683.     local f_args=1 # (device/nfs-path/directory) ->
  5684.  
  5685.     Check_Args $f_name $f_args $# "$@" || return 255
  5686.  
  5687.     while [ 1 ]; do
  5688.         rm -f /etc/mtab~
  5689.         Debug "unmounting $1 ..."
  5690.         umount $1 >$FILE_TMP_ERR 2>&1
  5691.         if [ $? -ne 0 ]; then
  5692.             fgrep "not mounted" $FILE_TMP_ERR >/dev/null && return 0
  5693.             fgrep "not found" $FILE_TMP_ERR >/dev/null && return 0
  5694.             Error2 UMOUNT_FAILED || return 1
  5695.         else
  5696.             return 0
  5697.         fi
  5698.     done
  5699. }
  5700.  
  5701. Get_Filesystem_Usage()
  5702. {
  5703.   local cut="1-10,18-28,37-45,47-53,56-"
  5704.  
  5705.   # CHECK-ray: 'used' right-aligns with number, not '%', thus
  5706.   #   extending space between 'used' and 'mount' ...
  5707.   echo "Filesystem   size(kB) free(kB)  used  mount point"
  5708.   if [ "$1" = "--install" ]; then
  5709.     shift
  5710.     if [ "$DIR_TARGET" != "/" ]; then
  5711.       # display ONLY target devices on their future mount points 
  5712.       df | cut -c $cut | \
  5713.          fgrep -v "Filesystem" | \
  5714.          fgrep '/root' | \
  5715.          sed 's: /root/linux: /:' | \
  5716.          sed 's: /root: /:' | \
  5717.          sed 's://:/:'
  5718.     else
  5719.       df -t ext2 | cut -c $cut | \
  5720.          fgrep -v "Filesystem"
  5721.     fi
  5722.   elif [ -e "$1" ]; then
  5723.     df $1 | cut -c $cut | \
  5724.        fgrep -v "Filesystem" 
  5725.   else
  5726.     df | cut -c $cut | \
  5727.        fgrep -v "Filesystem"  
  5728.   fi
  5729. }
  5730.  
  5731. # Get_Partition_Info ( { --boot, --size, --id, --type} PARTITION )
  5732. #
  5733. # return:
  5734. # 0    ok
  5735. # 1    no partition specified
  5736. # 2    partition not found
  5737. # 3    no value available
  5738. #
  5739. Get_Partition_Info()
  5740. {
  5741.     FUNC_NAME=Get_Partition_Info
  5742.     local field=
  5743.  
  5744.     # Debug "Get_Partition_Info: $@"
  5745.     if [ $# -gt 0 ]; then
  5746.         if [ "$1" = '--boot' ]; then
  5747.             field=3
  5748.             shift 1
  5749.         elif [ "$1" = '--size' ]; then
  5750.             field=4
  5751.             shift 1
  5752.         elif [ "$1" = '--id' ]; then
  5753.             field=5
  5754.             shift 1
  5755.         elif [ "$1" = '--type' ]; then
  5756.             field=6
  5757.             shift 1
  5758.         else
  5759.             field=
  5760.         fi
  5761.     fi
  5762.  
  5763.     Check_Partition_Valid $1 || return 1
  5764.     dummy="`sysinfo -P $1 --partition --var 2>&1 >/dev/null | cut -d':' -f $field`"
  5765.  
  5766.     if [ -z "$dummy" ]; then
  5767.         Error "no value available for field $field"
  5768.         return 3
  5769.     fi
  5770.     # Debug "Get_Partition_Info: result = <$dummy>"
  5771.     echo "$dummy"
  5772.     return 0
  5773. }
  5774.  
  5775. Build_FLOPPY()
  5776. {
  5777.     local val1=
  5778.     local val2=
  5779.  
  5780.     val1=" (`Get_Val CONF_FLOPPY1_DEV`)"
  5781.     val2=" (`Get_Val CONF_FLOPPY2_DEV`)"
  5782.  
  5783.     if [ -n "$val1" ]; then
  5784.         echo "--default \"1\" \\"
  5785.     elif [ -n "$val2" ]; then
  5786.         echo "--default \"2\" \\"
  5787.     fi
  5788.  
  5789.     if [ "$val1" = " ()" ]; then
  5790.         val1=
  5791.     fi
  5792.     echo "\"1\" \":FLOPPY_DRIVE: A $val1\" \\" 
  5793.  
  5794.     if [ "$val2" = " ()" ]; then
  5795.         val2=
  5796.     fi
  5797.     echo "\"2\" \":FLOPPY_DRIVE: B $val2\" \\" 
  5798. }
  5799.  
  5800. Build_FLOPPY_DEV()
  5801. {
  5802.     List box FLOPPY_DEV $1
  5803.     cat << EOF
  5804. "/dev/fd$1"      ":TYPE_FLOPPY_AUTO:" \\
  5805. EOF
  5806. }
  5807.  
  5808. Menu_Config_Floppy()
  5809. {
  5810.     local drive=
  5811.     local val=
  5812.  
  5813.     while [ 1 ]; do
  5814.         Choose --none --other --menu --build "Build_FLOPPY" FLOPPY 1 || return 1
  5815.         drive=$ANSWER
  5816.         val="`do_calc $drive - 1`"
  5817.         Choose --none --other --build "Build_FLOPPY_DEV ${val}" FLOPPY_DEV CONF_FLOPPY${drive}_DEV || return 1
  5818.         Do_Store CONF_FLOPPY${drive}_DEV "$ANSWER"
  5819.     done
  5820. }
  5821.  
  5822. Menu_Harddisk_Parameters()
  5823. {
  5824.     local harddisk=
  5825.     local diskname=
  5826.     local cylinders=
  5827.     local heads=
  5828.     local sectors=
  5829.     local geometry=
  5830.  
  5831.     if [ $# -ne 1 ]; then
  5832.         Panic ":ERR_WRONG_NUM_OF_ARGS:"
  5833.     fi
  5834.  
  5835.     harddisk=$1
  5836.     diskname="`echo $harddisk | sed 's/^\/dev\///'`"
  5837.  
  5838.     geometry="`Get_Val CONF_DISK_GEOMETRY_$diskname`" 2> /dev/null
  5839.     if [ -z "$geometry" ]; then
  5840.         geometry="`sysinfo --var --disk $harddisk 2>&1 >/dev/null | cut -d: -f 3,4,5 `"
  5841.         IFS=':' read cylinders heads sectors << EOF
  5842. $geometry
  5843. EOF
  5844.     else
  5845.         read cylinders heads sectors << EOF
  5846. $geometry
  5847. EOF
  5848.     fi
  5849.  
  5850.     while [ 1 ]; do
  5851.         # Ask_Bool --pretext ":HARDDISK: $harddisk ; CHS=$cylinders/$heads/$sectors ; " HARDDISK_PARAMETERS || return 1
  5852.         Ask_Bool --text ":HARDDISK: $harddisk ; CHS=$cylinders/$heads/$sectors ; :ASK_HARDDISK_PARAMETERS_HELP:" HARDDISK_PARAMETERS || return 1
  5853.         case $ANSWER in
  5854.         0)
  5855.             break
  5856.             ;;
  5857.         1)
  5858.             # Cylinders
  5859.             Ask_String CYLINDERS $cylinders || return 1
  5860.             cylinders="$ANSWER"
  5861.  
  5862.             # Heads
  5863.             Ask_String HEADS $heads || return 1
  5864.             heads="$ANSWER"
  5865.             
  5866.             # Sectors
  5867.             Ask_String SECTORS $sectors || return 1
  5868.             sectors="$ANSWER"
  5869.             ;;
  5870.         esac
  5871.     done
  5872.     Do_Store CONF_DISK_GEOMETRY_$diskname "$heads $sectors $cylinders"
  5873. }
  5874.  
  5875. # returns 0 on mke2fs success
  5876. # returns 1 on error or abort
  5877. # returns 2 of mke2fs was skipped
  5878. #
  5879. Menu_Call_Mke2fs()
  5880. {
  5881.     local badblocks_flag=
  5882.     local reserved_flag=
  5883.     local inodes_flag=
  5884.     local partid=
  5885.  
  5886.     # FIXME. Set Name in text
  5887.     # test for type Linux native
  5888.     partid="`Get_Partition_Info --id $1`"
  5889.     if [ -n "$partid" -a "$partid" != "131" ]; then
  5890.         Error "Partition $1 ; :ERR_NO_LINUX_PARTITION:"
  5891.         return 1
  5892.     fi
  5893.  
  5894.     # test whether it's mounted
  5895.     mount | fgrep "$1 " >/dev/null 2>&1
  5896.     if [ $? -eq 0 ]; then
  5897.         Error "Partition $1 ; :ERR_PARTITION_ALREADY_MOUNTED:"
  5898.         return 1
  5899.     fi
  5900.  
  5901.     Ask_Bool --pretext "Partition $1 ; " CALL_MKE2FS || return 1
  5902.     if [ "$ANSWER" = "1" ]; then return 2 ; fi
  5903.     Is_Expert
  5904.     if [ $? -eq 0 ]; then
  5905.         while [ 1 ]; do
  5906.             # Ask_String MKE2FS_INODES "4096"
  5907.             Ask_String --pretext "Partition $1 ; " MKE2FS_INODES "4096" || return 1
  5908.             if [ -n "$ANSWER" ]; then
  5909.                 if [ $ANSWER -gt 1023 ]; then break ; fi
  5910.             fi
  5911.             Error ":ERR_INVALID_ANSWER:" || return 1
  5912.         done
  5913.         inodes_flag="-i $ANSWER"
  5914.         while [ 1 ]; do
  5915.             # Ask_String MKE2FS_RESERVED "5"
  5916.             Ask_String --pretext "Partition $1 ; " MKE2FS_RESERVED "5" || return 1
  5917.             if [ -n "$ANSWER" ]; then
  5918.                 if [ 0 -le $ANSWER -a $ANSWER -lt 100 ]; then break ; fi
  5919.             fi
  5920.             Error ":ERR_INVALID_ANSWER:"
  5921.         done
  5922.         reserved_flag="-m $ANSWER"
  5923.     fi
  5924.     badblocks_flag="-c"
  5925.     Ask_Bool --pretext "Partition $1 ; " MKE2FS_BADBLOCKS n || return 1
  5926.     if [ "$ANSWER" = "1" ]; then
  5927.         badblocks_flag=
  5928.     fi
  5929.     Do_Clear_Screen
  5930.     prep_use PREPARE || return 1
  5931.     $DO_SIMULATE mke2fs $badblocks_flag $reserved_flag $inodes_flag $1 2>&1 || return 1
  5932.     return 0
  5933. }
  5934.  
  5935. Menu_Call_Fdisk()
  5936. {
  5937.   local diskname
  5938.   local mbrfile
  5939.   local crc1
  5940.   local crc2
  5941.   local fdisk_retval
  5942.  
  5943.   if [ $# -ne 1 ]; then
  5944.     Panic ":ERR_WRONG_NUM_OF_ARGS:"
  5945.   fi
  5946.  
  5947.   Check_Disk_Geometry $1
  5948.   if [ $? -ne 0 ]; then
  5949.     Menu_Harddisk_Parameters $1
  5950.   fi
  5951.  
  5952.   diskname="`echo $1 | sed 's/^\/dev\///'`"
  5953.   mbrfile=$DIR_LST_TMP/mbr${diskname}
  5954.  
  5955.   # safe boot sector before calling fdisk
  5956.   dd if=$1 of=$mbrfile bs=512 count=1 >/dev/null 2>&1
  5957.   gzip -f $mbrfile
  5958.  
  5959.   $CMD_BOX --help ":MENU_CALL_FDISK_HELP:" \
  5960. --title ":MENU_CALL_FDISK_TITLE:" \
  5961. --bool ":MENU_CALL_FDISK_TEXT:" 2> $FILE_TMP_ANSWER || return 1
  5962.   ANSWER="`cat $FILE_TMP_ANSWER`"
  5963.   if [ "$ANSWER" != "0" ]; then return 1 ; fi
  5964.   Do_Clear_Screen
  5965.   if [ -f /mnt/install/live/lisa/usr/doc/LST/use-fdisk.gz ]; then
  5966.     zcat /mnt/install/live/lisa/usr/doc/LST/use-fdisk.gz
  5967.   else
  5968.     if [ -f /usr/doc/LST/use-fdisk.gz ]; then
  5969.       zcat /usr/doc/LST/use-fdisk.gz
  5970.     fi
  5971.   fi
  5972.   fdisk "$1"
  5973.   fdisk_retval="$?"
  5974.  
  5975.   # safe boot sector after calling fdisk
  5976.   dd if=$1 of=$mbrfile.new bs=512 count=1 >/dev/null 2>&1
  5977.   gzip -f $mbrfile.new
  5978.  
  5979.   # compare by gzip CRC (no space for cmp or diff on rootdisk)
  5980.   crc1="`gzip -vl $mbrfile.gz | fgrep mbr${diskname} | cut -c 7-14`"
  5981.   crc2="`gzip -vl $mbrfile.new.gz | fgrep mbr${diskname}.new | cut -c 7-14`"
  5982.   if [ "$crc1" != "$crc2" ]; then
  5983.     Warn ":WARN_PARTITION_TABLE_MODIFIED:"
  5984.     if [ $fdisk_retval != 0 ]; then
  5985.       export NEED_TO_REBOOT=true
  5986.     else
  5987.       export NEED_TO_REBOOT=possible
  5988.     fi
  5989.   fi
  5990.   rm -f $mbrfile.gz $mbrfile.new.gz
  5991.   return 0
  5992. }
  5993.  
  5994. Menu_Config_Harddisk()
  5995. {
  5996.     local command
  5997.     local harddisk
  5998.     local partition
  5999.  
  6000.       while [ 1 ]; do
  6001.         $CMD_BOX --help ":MENU_CONFIG_HARDDISK_HELP:" \
  6002. --title ":MENU_CONFIG_HARDDISK_TITLE:" \
  6003. --menu ":MENU_CONFIG_HARDDISK_TEXT:" \
  6004. "Menu_Harddisk_Parameters" ":MENU_HARDDISK_PARAMETERS:" \
  6005. "Menu_Call_Fdisk" ":MENU_CALL_FDISK:" \
  6006. "Menu_Call_Mke2fs" ":MENU_CALL_MKE2FS:" 2> $FILE_TMP_ANSWER || return 1
  6007.         command="`cat $FILE_TMP_ANSWER`"
  6008.         case $command in
  6009.         Menu_Call_Mke2fs)
  6010.             Choose --menutitle ":CHOOSE_PARTITION_MENUTITLE:" --build "Build_PARTITION Linux" PARTITION || return 1
  6011.             partition="$ANSWER"    
  6012.             $command $partition
  6013.             ;;
  6014.         Menu_Call_Fdisk|Menu_Harddisk_Parameters)
  6015.             Choose --other HARDDISK_DEV || continue
  6016.             harddisk="$ANSWER"    
  6017.             # FIXME: real GEOMETYRY
  6018.             $command $harddisk
  6019.             ;;
  6020.         esac
  6021.     done
  6022. }
  6023.  
  6024. Menu_Show_Mounted()
  6025. {
  6026.     mount > $FILE_TMP_COMMAND
  6027.     $CMD_BOX --help ":MENU_SHOW_MOUNTED_HELP:" \
  6028. --title ":MENU_SHOW_MOUNTED_TITLE:" \
  6029. --text ":MENU_SHOW_MOUNTED_TEXT:" \
  6030. --browse $FILE_TMP_COMMAND 2> $FILE_TMP_ANSWER || return 1
  6031.     return 0
  6032. }
  6033.  
  6034. Menu_Show_Fstab()
  6035. {
  6036.     $CMD_BOX --help ":MENU_SHOW_FSTAB_HELP:" \
  6037. --title ":MENU_SHOW_FSTAB_TITLE:" \
  6038. --text ":MENU_SHOW_FSTAB_TEXT:" \
  6039. --browse $FILE_ETC_FSTAB 2> $FILE_TMP_ANSWER || return 1
  6040.     return 0
  6041. }
  6042.  
  6043. Menu_Fstab_Entry_Add()
  6044. {
  6045.     local dummy=
  6046.     local partition=
  6047.     local partid=
  6048.     local mounttype=
  6049.     local mountpoint=
  6050.     local mountopts=
  6051.  
  6052.     while [ 1 ]; do
  6053.         rm -f $FILE_ETC_FSTAB.tmp
  6054.         mounttype=
  6055.         while [ 1 ]; do
  6056.             $CMD_BOX --help ":MENU_FSTAB_ENTRY_ADD_HELP:" \
  6057. --title ":MENU_FSTAB_ENTRY_ADD_TITLE:" \
  6058. --string ":MENU_FSTAB_ENTRY_ADD_TEXT:" 2> $FILE_TMP_ANSWER || return 1
  6059.             partition="`cat $FILE_TMP_ANSWER`"
  6060.             sed -n "\,^$partition[     ]*,p" $FILE_ETC_FSTAB > $FILE_TMP_VAL
  6061.             if [ -s $FILE_TMP_VAL ]; then
  6062.                 Error --file $FILE_TMP_VAL ":ERR_FSTAB_ENTRY_EXISTS:"
  6063.                 continue
  6064.             else
  6065.                 rm -f $FILE_TMP_VAL
  6066.                 break
  6067.             fi
  6068.         done
  6069.         # test for type NFS
  6070.         if [ -n "`echo $partition | sed -n '/:/p'`" ]; then
  6071.             Debug "NFS-entry: <$partition>" 
  6072.             mounttype="nfs"
  6073.         else
  6074.             # test for other types
  6075.             Debug "Partition-entry: <$partition>" 
  6076.             Debug "Calling Check_Partition_Valid $partition" 
  6077.             Check_Partition_Valid $partition
  6078.             if [ $? -ne 0 ]; then 
  6079.                 Error "$partition is not a valid partition!"
  6080.                 continue
  6081.             fi
  6082.             # Get partition id
  6083.             Debug "Calling Get_Partition_Info --id $partition" 
  6084.             partid="`Get_Partition_Info --id $partition`"
  6085.             Debug "partid=<$partid>" 
  6086.             if [ -z "$partid" ]; then
  6087.                 Error "partition-id of $partition could not be determined!"
  6088.                 continue
  6089.             fi
  6090.             case $partid in
  6091.             1|4|6|11|12|14)
  6092.                 mounttype="msdos"
  6093.                 ;;
  6094.             7)
  6095.                 mounttype="hpfs"
  6096.                 ;;
  6097.             128|129)
  6098.                 mounttype="minix"
  6099.                 ;;
  6100.             130)
  6101.                 mounttype="swap"
  6102.                 ;;
  6103.             131)
  6104.                 mounttype="ext2"
  6105.                 ;;
  6106.             *)
  6107.                 Error "unknown partition-id $partid!"
  6108.                 continue
  6109.                 ;;
  6110.             esac
  6111.         fi
  6112.  
  6113.         if [ "$mounttype" = "swap" ]; then
  6114.             echo "$partition    none    swap default 0 0" > $FILE_ETC_FSTAB.tmp
  6115.         else
  6116.             $CMD_BOX --help ":MENU_FSTAB_ENTRY_ADD_MOUNTPOINT_HELP:" \
  6117. --title ":MENU_FSTAB_ENTRY_ADD_MOUNTPOINT_TITLE:" \
  6118. --string ":MENU_FSTAB_ENTRY_ADD_MOUNTPOINT_TEXT:" 2> $FILE_TMP_ANSWER
  6119.             if [ $? -ne 0 ]; then continue; fi
  6120.             mountpoint="`cat $FILE_TMP_ANSWER`"
  6121.  
  6122.             if [ "$mounttype" = "hpfs" ]; then
  6123.                 mountopts="ro";
  6124.             else
  6125.                 $CMD_BOX --help ":MENU_FSTAB_ENTRY_ADD_MOUNTOPTS_HELP:" \
  6126. --title ":MENU_FSTAB_ENTRY_ADD_MOUNTOPTS_TITLE:" \
  6127. --menu ":MENU_FSTAB_ENTRY_ADD_MOUNTOPTS_TEXT:" \
  6128. "rw" ":MOUNT_TYPE_READ_WRITE:" \
  6129. "ro" ":MOUNT_TYPE_READ_ONLY:" 2> $FILE_TMP_ANSWER
  6130.                 if [ $? -ne 0 ]; then continue; fi
  6131.                 mountopts="`cat $FILE_TMP_ANSWER`"
  6132.             fi
  6133.  
  6134.             if [ "$mounttype" = "nfs" ]; then
  6135.                 echo "$partition    $mountpoint    $mounttype    soft,bg,intr,nodev,nosuid,$mountopts 0 0" > $FILE_ETC_FSTAB.tmp
  6136.             else    
  6137.                 echo "$partition    $mountpoint    $mounttype $mountopts 0 2" > $FILE_ETC_FSTAB.tmp
  6138.             fi
  6139.         fi
  6140.  
  6141.         if [ ! -d $mountpoint ]; then
  6142.             mkdir -p $mountpoint
  6143.         fi 
  6144.         cat $FILE_ETC_FSTAB.tmp >> $FILE_ETC_FSTAB
  6145.         Msg ":INFO_MOUNT_REBOOT:"
  6146.         return 0
  6147.     done
  6148. }
  6149.  
  6150. Menu_Fstab_Entry_Del()
  6151. {
  6152.     local del_entry=
  6153.  
  6154.     echo "$CMD_BOX --help \":MENU_FSTAB_ENTRY_DEL_HELP:\" --title \":MENU_FSTAB_ENTRY_DEL_TITLE:\" --one \":MENU_FSTAB_ENTRY_DEL_TEXT:\" \\" > $FILE_TMP_COMMAND
  6155.     Build_Fstab_Menu
  6156.     sh $FILE_TMP_COMMAND || return 1
  6157.     del_entry="`cat $FILE_TMP_ANSWER`"
  6158.  
  6159.     $CMD_BOX --help ":MENU_FSTAB_ENTRY_DEL_ACK_HELP:" \
  6160. --title ":MENU_FSTAB_ENTRY_DEL_ACK_TITLE:" \
  6161. --bool "$del_entry ; :MENU_FSTAB_ENTRY_DEL_ACK_TEXT:" 2> $FILE_TMP_ANSWER || return 1
  6162.     ANSWER="`cat $FILE_TMP_ANSWER`"
  6163.     case $ANSWER in
  6164.     0)
  6165.         sed "\,^$del_entry,d" $FILE_ETC_FSTAB > $FILE_ETC_FSTAB.tmp
  6166.         mv $FILE_ETC_FSTAB.tmp $FILE_ETC_FSTAB
  6167.         return 0
  6168.         ;;
  6169.     1)
  6170.         return 1
  6171.         ;;
  6172.     esac
  6173. }
  6174.  
  6175. Menu_Config_Mount()
  6176. {
  6177.     while [ 1 ]; do
  6178.         $CMD_BOX --help ":MENU_CONFIG_MOUNT_HELP:" \
  6179. --title ":MENU_CONFIG_MOUNT_TITLE:" \
  6180. --menu ":MENU_CONFIG_MOUNT_TEXT:" \
  6181. "Menu_Show_Mounted" ":MENU_SHOW_MOUNTED:" \
  6182. "Menu_Show_Fstab" ":MENU_SHOW_FSTAB:" \
  6183. "Menu_Fstab_Entry_Add" ":MENU_FSTAB_ENTRY_ADD:" \
  6184. "Menu_Fstab_Entry_Del" ":MENU_FSTAB_ENTRY_DEL:" 2> $FILE_TMP_ANSWER
  6185.         COMMAND="`cat $FILE_TMP_ANSWER`"
  6186.         if [ -z "$COMMAND" ]; then
  6187.             break
  6188.         fi
  6189.         $COMMAND
  6190.     done
  6191.     rm -f $FILE_ETC_FSTAB.tmp
  6192.     return 0
  6193. }
  6194.  
  6195. Show_Filesystem_Usage()
  6196. {
  6197.     Get_Filesystem_Usage $1 > $FILE_TMP_VAL
  6198.     Browse2 $FILE_TMP_VAL FILESYSTEM_USAGE
  6199. }
  6200.  
  6201.  
  6202. # libLSTfirst - first install library shared between several scripts
  6203. #
  6204. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  6205. #
  6206.  
  6207. Recover_COL11_Strings()
  6208. {
  6209.     local my_lang="`Get_Val CONF_LST_LANG`"
  6210.  
  6211.     case $my_lang in
  6212.     de|us)
  6213.         ;;
  6214.     *)
  6215.         my_lang=us
  6216.         set_val CONF_LST_LANG us
  6217.         ;;
  6218.     esac
  6219.  
  6220.     Debug "trying to recover libLSTtext ($my_lang) from COL 1.1 CD"
  6221.     zcat /mnt/col/launch/dos/initrd.gz > /dev/ram2
  6222.     mkdir -p /ram2
  6223.     mount -t ext2 /dev/ram2 /ram2
  6224.     # filter out my_lang
  6225.     zcat /ram2/usr/lib/LST/libLSTtext.gz | sed "{
  6226.         s/^${my_lang}-x> //
  6227.         s/^x-x> //
  6228.         /^..-x> /d
  6229.         }" > /ram2/usr/lib/LST/libLSTtext
  6230.     Debug "merging with source file /ram2/usr/lib/LST/libLSTtext"
  6231.     Do_Merge_libLSTtext /usr/lib/LST/libLSTtext /ram2/usr/lib/LST/libLSTtext
  6232.     Debug "merging done"
  6233.     if [ -f /bin/freeramdisk.gz ]; then
  6234.         gunzip /bin/freeramdisk
  6235.     fi
  6236.     if [ -f /bin/freeramdisk ]; then
  6237.         freeramdisk /dev/ram2
  6238.     fi
  6239.     umount /ram2
  6240.     rm -fr /ram2
  6241. }
  6242.  
  6243. Do_Read_Source()
  6244. {
  6245.   local my_lang="`Get_Val CONF_LST_LANG`"
  6246.  
  6247.   Debug "CONF_LST_LANG=$my_lang"
  6248.  
  6249.   Info ":INFO_WAIT:"
  6250.   # check if we have pkg infos in the install tree
  6251.   for i in meta.db pkgs.all pkgs.db pkgs.idx pkgs.min pkgs.rec ; do
  6252.     if [ -f $DIR_DATA/$i ]; then
  6253.       Debug "using source file $DIR_DATA/$i"
  6254.       cp -a $DIR_DATA/$i /usr/lib/LST/$i
  6255.     fi
  6256.   done
  6257.   if [ -f $DIR_DATA/$my_lang/pkgs.idx ]; then
  6258.     Debug "using source file $DIR_DATA/$my_lang/pkgs.idx"
  6259.     cp -a $DIR_DATA/$my_lang/pkgs.idx /usr/lib/LST/pkgs.idx
  6260.   elif [ -f $DIR_DATA/us/pkgs.idx ]; then
  6261.     # if language specific not available use english
  6262.     Debug "using source file $DIR_DATA/us/pkgs.idx"
  6263.     cp -a $DIR_DATA/us/pkgs.idx /usr/lib/LST/pkgs.idx
  6264.   fi
  6265.   if [ "$INSTALL_MODE" = "OpenLinux" ]; then
  6266.     if [ -f $DIR_DATA/$my_lang/libLSTtext ]; then
  6267.       Debug "merging with source file $DIR_DATA/$my_lang/libLSTtext"
  6268.       Do_Merge_libLSTtext /usr/lib/LST/libLSTtext $DIR_DATA/$my_lang/libLSTtext
  6269.       Debug "merging done"
  6270.     elif [ -f $DIR_DATA/us/libLSTtext ]; then
  6271.       # if language specific not available use english
  6272.       Debug "merging with source file $DIR_DATA/us/libLSTtext"
  6273.       Do_Merge_libLSTtext /usr/lib/LST/libLSTtext $DIR_DATA/us/libLSTtext
  6274.       Debug "merging done"
  6275.     # NT does not properly handle TRANS.TBL files
  6276.     elif [ -f $DIR_DATA/$my_lang/liblstte ]; then
  6277.       Debug "merging with source file $DIR_DATA/$my_lang/liblstte"
  6278.       Do_Merge_libLSTtext /usr/lib/LST/libLSTtext $DIR_DATA/$my_lang/liblstte
  6279.       Debug "merging done"
  6280.     # NT does not properly handle TRANS.TBL files
  6281.     elif [ -f $DIR_DATA/us/liblstte ]; then
  6282.       Debug "merging with source file $DIR_DATA/us/liblstte"
  6283.       Do_Merge_libLSTtext /usr/lib/LST/libLSTtext $DIR_DATA/us/liblstte
  6284.       Debug "merging done"
  6285.     fi
  6286.   fi
  6287.   # this is to still support COL 1.1 installs as good as possible
  6288.   if [ -f /mnt/col/install/RPMS/lisa-2.3-7.i386.rpm ]; then
  6289.     Recover_COL11_Strings
  6290.   fi
  6291.   # check if we have private pkg infos in the install tree
  6292.   for i in meta.db pkgs.db pkgs.idx pkgs.sel ; do
  6293.     if [ -f $DIR_DATA/private/$i ]; then
  6294.       Debug "using source file $DIR_DATA/private/$i"
  6295.       cp -a $DIR_DATA/private/$i /usr/lib/LST/$i
  6296.     fi
  6297.   done
  6298.   # this is to check whether we have execute permissions
  6299.   for i in cpio rpm rpmextr ; do
  6300.     if [ ! -x /bin/$i ]; then
  6301.       chmod +x /bin/$i > /dev/null 2>&1
  6302.     fi
  6303.     if [ ! -x /bin/$i ]; then
  6304.       Msg "/bin/$i ; :ERR_MISSING_EXEC_PERMISSIONS:"
  6305.     fi
  6306.   done
  6307.   prep_use SELECT
  6308. }
  6309.  
  6310.  
  6311. # converts decimal number to it's hexadecimal representation
  6312. # on failure sets ERROR to an error message
  6313. #
  6314. Dec2Hex()
  6315. {
  6316.   # printf "%02x\n" $1
  6317.   # this would be too easy (and costs approx. 6k on floppy)...
  6318.   # so let's do it the HARD WAY(TM) !-)
  6319.   local n1=`do_calc $1 / 16`
  6320.   local t1=`do_calc $n1 \* 16`
  6321.   local n2=`do_calc $1 - $t1`
  6322.   local i=
  6323.   local r=""
  6324.   export ERROR=
  6325.   
  6326.   if [ "$1" -gt 255 ]; then
  6327.     ERROR="Dec2Hex: number too big ($1 > 255)"
  6328.     return 1
  6329.   fi
  6330.  
  6331.   if [ $n1 -eq 0 ]; then
  6332.       n1=0
  6333.   fi
  6334.  
  6335.   for i in $n1 $n2; do
  6336.     if [ $i -lt 10 ]; then
  6337.       r="${r}$i"
  6338.     else
  6339.       case "$i" in
  6340.         10) r="${r}a" ;;
  6341.         11) r="${r}b" ;;
  6342.         12) r="${r}c" ;;
  6343.         13) r="${r}d" ;;
  6344.         14) r="${r}e" ;;
  6345.         15) r="${r}f" ;;
  6346.     *) ERROR="Dec2Hex: illegal condition: remainder < 15"; return 1;;
  6347.       esac
  6348.     fi
  6349.   done
  6350.   
  6351.   echo "$r"
  6352.   return 0
  6353. }
  6354.  
  6355. Set_Real_Root()
  6356. {
  6357.   local root_dev=
  6358.   local driver=
  6359.   local disk=
  6360.   local base=
  6361.   local partition=
  6362.   local major=
  6363.   local minor=
  6364.   local high=
  6365.   local low=
  6366.   local bios_id=
  6367.  
  6368.   root_dev="`echo $1 | sed 's/^\/dev\///'`"
  6369.   driver="`echo $root_dev | cut -c 1-2`"
  6370.   if [ "$driver" = "rd" ]; then
  6371.     driver="`echo $root_dev | cut -c 1-5`"
  6372.     disk="`echo $root_dev | cut -c 7-7`"
  6373.     partition="`echo $root_dev | cut -c 9-`"
  6374.     base=8
  6375.   elif [ "$driver" = "id" ]; then
  6376.     driver="`echo $root_dev | cut -c 1-6`"
  6377.     disk="`echo $root_dev | cut -c 8-8`"
  6378.     partition="`echo $root_dev | cut -c 10-`"
  6379.     base=8
  6380.   else
  6381.     disk="`echo $root_dev | cut -c 3-3`"
  6382.     partition="`echo $root_dev | cut -c 4-`"
  6383.     base=64
  6384.   fi
  6385.  
  6386.   case $driver in
  6387.   hd)
  6388.     if [ "$disk" = "a" -o "$disk" = "b" ]; then major=3
  6389.     else major=22
  6390.     fi
  6391.     ;;
  6392.   ida/c0) major=72 ;;
  6393.   rd/c0) major=48 ;;
  6394.   sd)
  6395.     base=16
  6396.     major=8
  6397.     ;;
  6398.   xd) major=13 ;;
  6399.   esac
  6400.  
  6401.   high="`Dec2Hex $major`"
  6402.  
  6403.   case $disk in
  6404.   a|0) minor=0 ;;
  6405.   b|1) minor=1 ;;
  6406.   c|2)
  6407.       if [ "$driver" = "hd" ]; then
  6408.         minor=0
  6409.     else
  6410.         minor=2
  6411.     fi
  6412.     ;;
  6413.   d|3)
  6414.       if [ "$driver" = "hd" ]; then
  6415.         minor=1
  6416.     else
  6417.         minor=3
  6418.     fi
  6419.     ;;
  6420.   e|4) minor=4 ;;
  6421.   f|5) minor=5 ;;
  6422.   g|6) minor=6 ;;
  6423.   h|7) minor=7 ;;
  6424.   esac
  6425.  
  6426.   low="`do_calc $minor \* $base`"
  6427.   low="`do_calc $low \+ $partition`"
  6428.   low="`Dec2Hex $low`"
  6429.  
  6430.   bios_id="0x${high}${low}"
  6431.  
  6432.   Is_Expert
  6433.   if [ $? -eq 0 ]; then
  6434.     Ask_String ROOT_ID "$bios_id" || return 1
  6435.     bios_id="$ANSWER"
  6436.   fi
  6437.  
  6438.   if [ -n "$bios_id" ]; then
  6439.     echo "$bios_id" > /etc/rootdev
  6440.     echo "$bios_id" > /proc/sys/kernel/real-root-dev
  6441.   fi
  6442. }
  6443.  
  6444. Do_Reboot()
  6445. {
  6446.   Info ":INFO_REBOOTING:"
  6447.   sleep 3
  6448.   Do_Clear_Screen
  6449.   reboot
  6450. }
  6451.  
  6452. Menu_Config_Partitioning()
  6453. {
  6454.   local defval
  6455.   local trouble
  6456.  
  6457.   while [ 1 ]; do
  6458.     defval=n
  6459.     trouble=
  6460.  
  6461.     # do we have any target partition at all?
  6462.     if [ -z "`sysinfo -C Dest --notitle --noheader --partition`" ]; then
  6463.       trouble=NO_TARGET_AVAILABLE
  6464.       defval=y
  6465.     fi
  6466.  
  6467.     # do we have less than 12 MB but no swap partition?
  6468.     if [ `filesize /proc/kcore` -lt 12582912 -a \
  6469.     -z "`sysinfo -C Swap --notitle --noheader --partition`" ]; then
  6470.       trouble=NOT_ENOUGH_RAM
  6471.       defval=y
  6472.     fi
  6473.  
  6474.     Ask_Bool CALL_FDISK $defval || return 1
  6475.     if [ "$ANSWER" = "1" ]; then
  6476.       if [ -n "$trouble" ]; then
  6477.     echo "$trouble" >> $FILE_TMP_ERR
  6478.     Error2 $trouble
  6479.     continue
  6480.       fi
  6481.       return 0
  6482.     fi
  6483.  
  6484.     Do_Modify_Partitioning || continue
  6485.     break
  6486.   done
  6487.   return 0
  6488. }
  6489.  
  6490.  
  6491. Do_Modify_Partitioning()
  6492. {
  6493.   local retval=1
  6494.  
  6495.   while [ 1 ]; do
  6496.     while [ 1 ]; do
  6497.       # ask for hard disk    
  6498.       Choose --none --other --build Build_HARDDISK_DEV HARDDISK_DEV || break
  6499.       if [ -z "$ANSWER" ]; then
  6500.         retval=0
  6501.         break
  6502.       fi
  6503.       Menu_Call_Fdisk "$ANSWER" || continue
  6504.     done
  6505.     if [ -n "$NEED_TO_REBOOT" ]; then
  6506.       Ask_Bool NEED_TO_REBOOT || continue
  6507.       if [ "$ANSWER" = "0" ]; then Do_Reboot ; fi
  6508.     fi
  6509.     break
  6510.   done
  6511.   return $retval
  6512. }
  6513.  
  6514. Fix_uucp()
  6515. {
  6516.   local i
  6517.  
  6518.   for i in /var/spool/uucp /var/spool/uucppublic ; do
  6519.     mkdir -p $DIR_TARGET${i}
  6520.     chown uucp.uucp $DIR_TARGET${i}
  6521.     chmod 1777 $DIR_TARGET${i}
  6522.   done
  6523.  
  6524.   i=/var/log/uucp
  6525.  
  6526.   touch $DIR_TARGET${i}
  6527.   chown uucp.uucp $DIR_TARGET${i}
  6528.   if [ -d $DIR_TARGET${i} ]; then
  6529.     chmod 775 $DIR_TARGET${i}
  6530.   else
  6531.     chmod 664 $DIR_TARGET${i}
  6532.   fi
  6533. }
  6534.  
  6535. Fix_sendmail_start()
  6536. {
  6537.   set_val -f /root/etc/sysconfig/daemons/sendmail ONBOOT yes
  6538. }
  6539.  
  6540. Fix_httpd_start()
  6541. {
  6542.   # this fix is for apache-1.1.1-10
  6543.   if [ -d /root/usr/doc/apache-httpd-1.1.1-10 -a \
  6544.       ! -f /root/etc/sysconfig/daemons/httpd ]; then
  6545.     cat << EOD  > /root/etc/sysconfig/daemons/httpd
  6546. IDENT=WWW
  6547. DESCRIPTIVE="WEB server"
  6548. ONBOOT=no
  6549. VARIANT=apache
  6550. EOD
  6551.   fi
  6552.   set_val -f /root/etc/sysconfig/daemons/httpd ONBOOT yes
  6553. }
  6554.  
  6555. Fix_passwd()
  6556. {
  6557.     local nis_magic
  6558.  
  6559.     # grep out root account (with password) and adjust HOME
  6560.     sed -n '/^root:/p' /etc/passwd | sed 's/:\/:/:\/root:/' > /etc/passwd.tmp
  6561.  
  6562.     # append normal passwd (without root account)
  6563.     sed '/^root:/d' $DIR_TARGET/etc/passwd >> /etc/passwd.tmp
  6564.  
  6565.     nis_magic="`sed -n '/^+/p' /etc/passwd.tmp`"
  6566.     if [ -n "$nis_magic" ]; then
  6567.         sed '/^+/d' /etc/passwd.tmp > /etc/passwd.nismagic
  6568.         mv -f /etc/passwd.nismagic /etc/passwd.tmp
  6569.     fi
  6570.  
  6571.     # grep out normal account (with password)
  6572.     if [ -n "$LAST_USER" ]; then
  6573.         sed -n "/^$LAST_USER:/p" /etc/passwd >> /etc/passwd.tmp
  6574.     fi
  6575.     if [ -n "$nis_magic" ]; then
  6576.         echo "$nis_magic" >> /etc/passwd.tmp
  6577.     fi
  6578.  
  6579.     # on COL 2.2 setup does not provide a passwd, so we have to fix ours
  6580.     sed '{
  6581.         /^install/d
  6582.         /^expert/d
  6583.         /^setup/d
  6584.         /^hilfe/d
  6585.         /^help/d
  6586.         s/Nobody:\/:/Nobody:\/:\/bin\/false/
  6587.         }' /etc/passwd.tmp > /etc/passwd.tmp2
  6588.     mv /etc/passwd.tmp2 /etc/passwd.tmp
  6589.  
  6590.     chown root.root /etc/passwd.tmp
  6591.     chmod 644 /etc/passwd.tmp
  6592.     mv /etc/passwd.tmp $DIR_TARGET/etc/passwd
  6593.  
  6594.     # if we are on a COL 1.2 install then switch to shadow passwords
  6595.     if [ "$INSTALL_MODE" = "OpenLinux" -a -x $DIR_TARGET/usr/sbin/pwconv ]; then
  6596.         Debug "calling pwconv to switch to shadow passwords"
  6597.         History_Install "calling pwconv to switch to shadow passwords"
  6598.         ( cd $DIR_TARGET; chroot $DIR_TARGET usr/sbin/pwconv ) > $DIR_TARGET/install/pwconv.error 2>&1
  6599.         # remove empty error logs
  6600.         if [ ! -s $DIR_TARGET/install/pwconv.error ]; then
  6601.             rm -f $DIR_TARGET/install/pwconv.error
  6602.         fi
  6603.     fi
  6604.     return 0
  6605. }
  6606.  
  6607. Menu_First_Install()
  6608. {
  6609.     export INSTALL_STATE=3
  6610.     local disk=
  6611.     local partition=
  6612.     local orig_source=
  6613.     local orig_dev=
  6614.     local orig_mode=
  6615.     local max_state_seen=-1
  6616.     local instpkg="$DIR_LIVE/lizard/share/apps/lizard/extrabin/instpkg.sh"
  6617.  
  6618.     History "`date` $LOGNAME: LISA: first time install (${MODE_USER}-mode)"
  6619.     # FIXME: late fix for Caldera scd
  6620.     mv $FILE_SYSTEM_CONF $FILE_SYSTEM_CONF.tmp
  6621.     sed -e 's:/dev/sr:/dev/scd:g' < $FILE_SYSTEM_CONF.tmp > $FILE_SYSTEM_CONF
  6622.     rm -f $FILE_SYSTEM_CONF.tmp
  6623.  
  6624.     if [ -f /var/run/cardmgr.pid ]; then
  6625.         rm -f /sbin/cardmgr
  6626.         rm -fr /etc/pcmcia
  6627.         kill -9 `cat /var/run/cardmgr.pid`
  6628.     fi
  6629.  
  6630.     while [ 1 ]; do
  6631.         INSTALL_STATE="`do_calc $INSTALL_STATE - 1`"
  6632.         Debug "entering install stage $INSTALL_STATE ..."
  6633.         if [ $INSTALL_STATE -gt $max_state_seen ]; then
  6634.             max_state_seen=$INSTALL_STATE
  6635.         fi
  6636.         case $INSTALL_STATE in
  6637.         0)
  6638.             # quit LISA
  6639.             end_use INSTALL
  6640.             end_use CALDERA_INSTALL
  6641.             end_use RPM_INSTALL
  6642.             end_use /usr/lib/LST/libLSTall
  6643.             return 1
  6644.             ;;
  6645.         1)
  6646.             # quit LISA
  6647.             Debug "User wanted to exit LISA. Not allowed in First_Install"
  6648.             return 1
  6649.             ;;
  6650.         2)
  6651.             # initial module management
  6652.             InitSubsystems || continue
  6653.             # exit now if we used "boot root=/dev/sdXX" at LILO prompt
  6654.             if [ -f /etc/install.skip ]; then
  6655.                 sync
  6656.                 Do_Clear_Screen
  6657.                 exit 0
  6658.             fi
  6659.             ;;
  6660.         3)
  6661.             # allow repartitioning as soon as possible
  6662.             Debug "Before Menu_Config_Partitioning"
  6663.             Menu_Config_Partitioning || continue
  6664.             Debug "After Menu_Config_Partitioning"
  6665.             ;;
  6666.         4)
  6667.             # enable swapspace as soon as possible
  6668.             # FIXME: omit this question if swapspace was already set up
  6669.             Menu_Config_Swap || continue
  6670.             # FIXME: check if we have less than 12 MB but no swap enabled?
  6671.             ;;
  6672.         5)
  6673.             # choose install source (floppy, hard disk, CDROM, network, ...)
  6674.             Choose_Install_Source || continue
  6675.             # do read files from source
  6676.             Do_Read_Source
  6677.             ;;
  6678.         6)
  6679.             # select target partition(s)
  6680.             prep_use PREPARE
  6681.             Choose_Install_Target || continue
  6682.             end_use PREPARE
  6683.             # do init target partition(s)
  6684.             Do_Init_Target
  6685.             ;;
  6686.         7)
  6687.             # choose packages
  6688.             prep_use SELECT
  6689.             Menu_Pkg_Select || continue
  6690.             ;;
  6691.         8)
  6692.             if [ -x $instpkg ]; then
  6693.                 # install packages using instpkg.sh
  6694.                 Info ":INFO_WAIT:"
  6695.                 Do_PHI_Complete_Pkgs
  6696.                 Do_Sort_Pkgs
  6697.                 Msg2 PKG_INSTALL || continue
  6698.                 # We have the target mounted under /root in
  6699.                 # LISA mode so we have to modify instpkg.sh)
  6700.                 umount $DIR_TARGET/proc > /dev/null 2>&1
  6701.                 sed '{
  6702.                     /^Target=\/mnt\/root/s/^Target=\/mnt\/root/Target=\/root/
  6703.                     }' $instpkg > /tmp/instpkg.sh
  6704.                 chmod 755 /tmp/instpkg.sh
  6705.                 Do_Clear_Screen
  6706.                 echo "Calling package install tool ..."
  6707.                 ( cd $DIR_TARGET ; /tmp/instpkg.sh $FILE_PKGS_SEL )
  6708.             else
  6709.                 # install packages the old way
  6710.                 prep_use INSTALL
  6711.                 Do_Pkg_Install || continue
  6712.                 end_use SELECT
  6713.                 end_use INSTALL
  6714.                 Do_Fixes_After_Pkg_Install
  6715.                 Do_Save_Package_Selection
  6716.             fi
  6717.             INSTALL_STATE="`do_calc $INSTALL_STATE + 1`"
  6718.             ;;
  6719.         9)
  6720.             # FIXME: issue a warning that backsptep means reinstall or reboot
  6721.             Error ":ERR_BACKSTEP_NOT_POSSIBLE:"
  6722.             Ask_Bool ABORT_INSTALL y
  6723.             if [ "$ANSWER" = "0" ]; then
  6724.                 Do_Reboot
  6725.             fi
  6726.             ;;
  6727.         10)
  6728.             # initial system configuration (to be replaced by COAS)
  6729.             Menu_First_Config || continue
  6730.             Do_Fixes_After_First_Config
  6731.             # umount the second mount of /proc
  6732.             umount /root/proc
  6733.             ;;
  6734.         11)
  6735.             History "`date` $LOGNAME: primary installation completed"
  6736.             History "==============================================================="
  6737.             # this file is used as a marker to show that the install is complete
  6738.             touch /etc/install.done
  6739.             umount /mnt >/dev/null 2>&1
  6740.             rmmod smbfs >/dev/null 2>&1
  6741.             if [ "`get_val -f /etc/lst.cnf CONF_COL_EDITION`" != "SBA" ]; then
  6742.                 Msg2 GRATULATIONS || continue
  6743.             fi
  6744.             # FIXME: need better method to find initrd
  6745.             if [ "`uname -r`" != "1.2.13" ]; then
  6746.                 sync
  6747.                 Do_Clear_Screen
  6748.                 exit 0
  6749.             else
  6750.                 Do_Reboot_System
  6751.             fi
  6752.             ;;
  6753.         esac
  6754.         INSTALL_STATE="`do_calc $INSTALL_STATE + 2`"
  6755.     done
  6756. }
  6757.  
  6758. Do_Set_Password()
  6759. {
  6760.     local username=$1
  6761.  
  6762.     prep_use /bin/passwd
  6763.     reset 2>&1
  6764.     Do_Clear_Screen
  6765.     # small passwd wrapper
  6766.     while [ 1 ]; do
  6767.         touch /tmp/.passwd
  6768.         echo "Setting password for $username:"
  6769.               if [ "$MODE_QUERY" = "auto" ]; then
  6770.             sleep 1 # sleep a second to make sure file is older
  6771.             sed "s/^$username:[^:]*:/$username:*notset*:/" /etc/passwd > /etc/passwd.tmp
  6772.             chown root.root /etc/passwd.tmp
  6773.             chmod 644 /etc/passwd.tmp
  6774.             mv /etc/passwd.tmp /etc/passwd
  6775.         else
  6776.             passwd $username 2>&1
  6777.         fi
  6778.         if [ /etc/passwd -nt /tmp/.passwd ]; then
  6779.             break
  6780.         fi
  6781.     done
  6782.     return 0
  6783. }
  6784.  
  6785. Do_Set_Root_Password()
  6786. {
  6787.     Msg2 SET_ROOT_PASSWD || return 1
  6788.     Do_Set_Password root
  6789.     return 0
  6790. }
  6791.  
  6792. Do_Create_First_User()
  6793. {
  6794.     Msg2 CREATE_FIRST_USER || return 1
  6795.     Menu_User_Add --first
  6796. }
  6797.  
  6798. Menu_Config_Network()
  6799. {
  6800.     local s=2
  6801.  
  6802.     while [ 1 ]; do
  6803.         s="`do_calc $s - 1`"
  6804.         Debug "entering net config stage $s ..."
  6805.         case $s in
  6806.         0)
  6807.             return 1
  6808.             ;;
  6809.         1)
  6810.             Menu_Config_FQ_Name || continue
  6811.             Do_Ifcfg lo up
  6812.             ;;
  6813.         2)
  6814.             Menu_Config_Ether || continue
  6815.             if [ "`Get_Val CONF_eth0_STAT`" != "up" -a \
  6816.             "`Get_Val CONF_tr0_STAT`" != "up" ]; then
  6817.                 # disable router, DNS and NIS
  6818.                 # (this is dumb but prevents from trouble)
  6819.                 # jump over the next steps
  6820.                 CONF_ROUTER1_IP=""
  6821.                 CONF_DNS_DOMAIN=""
  6822.                 CONF_DNS_SEARCH=""
  6823.                 CONF_DNS_SERVER1_IP=""
  6824.                 CONF_DNS_SERVER2_IP=""
  6825.                 CONF_DNS_SERVER3_IP=""
  6826.                 CONF_NIS_DOMAIN=""
  6827.                 CONF_NIS_SERVER1_IP=""
  6828.                 CONF_NIS_SERVER2_IP=""
  6829.                 CONF_NIS_SERVER3_IP=""
  6830.                 s=99
  6831.             fi
  6832.             ;;
  6833.         3)
  6834.             Menu_Config_Router first || continue
  6835.             ;;
  6836.         4)
  6837.             Menu_Config_DNS || continue
  6838.             ;;
  6839.         5)
  6840.             if [ -x $DIR_TARGET/usr/sbin/ypbind ]; then
  6841.                 Menu_Config_NIS || continue
  6842.             fi
  6843.             ;;
  6844.         *)
  6845.             return 0
  6846.             ;;
  6847.         esac
  6848.         s="`do_calc $s + 2`"
  6849.     done
  6850. }
  6851.  
  6852. Build_Daemons()
  6853. {
  6854.     local i
  6855.     local daemon
  6856.     local ghostdaemon
  6857.     local variant
  6858.     local descriptive
  6859.     local onboot
  6860.     local ident
  6861.     local desc
  6862.     local preset
  6863.     local have_mta=false
  6864.  
  6865.     for i in $DIR_TARGET/etc/sysconfig/daemons/* ; do
  6866.         if [ ! -f $i ]; then continue ; fi
  6867.         daemon="`basename $i`"
  6868.         if [ "$daemon" = "mta" ]; then
  6869.             have_mta=true
  6870.         fi
  6871.  
  6872.         # filter out wrong (old) sendmail/smail files if mta exists
  6873.         if [ "$daemon" = "sendmail" -a "$have_mta" = "true" ]; then
  6874.             continue
  6875.         fi
  6876.         if [ "$daemon" = "smail" -a "$have_mta" = "true" ]; then
  6877.             continue
  6878.         fi
  6879.  
  6880.         # filter out .rpmsave and .rpmorig files
  6881.         ghostdaemon="`basename $i .rpmsave`"
  6882.         if [ "$daemon" != "$ghostdaemon" ]; then continue ; fi
  6883.         ghostdaemon="`basename $i .rpmorig`"
  6884.         if [ "$daemon" != "$ghostdaemon" ]; then continue ; fi
  6885.  
  6886.         # filter out .*~ files
  6887.         if [ "`echo "$daemon" | sed 's/^.*\(.\)$/\1/'`" = '~' ]; then
  6888.             continue
  6889.         fi
  6890.  
  6891.         hack="$daemon"
  6892.         onboot="`get_val -f $i ONBOOT`"
  6893.         ident="`get_val -f $i IDENT`"
  6894.         case $ident in
  6895.         DOSEmu)
  6896.             hack="DOS Emulation"
  6897.             ;;
  6898.         lpd)
  6899.             hack="Print Server"
  6900.             ;;
  6901.         news-system)
  6902.             hack="News Server"
  6903.             ;;
  6904.         nis-server)
  6905.             hack="NIS Server"
  6906.             ;;
  6907.         MTA)
  6908.             hack="Mail Server"
  6909.             ;;
  6910.         NFS)
  6911.             hack="NFS Server"
  6912.             ;;
  6913.         SAMBA)
  6914.             hack="SMB Server"
  6915.             ;;
  6916.         WWW)
  6917.             hack="WEB server"
  6918.             ;;
  6919.         esac
  6920.         descriptive="`get_val -f $i DESCRIPTIVE`"
  6921.         if [ -n "$descriptive" ]; then
  6922.             hack="$descriptive"
  6923.         fi
  6924.         variant="`get_val -f $i VARIANT`"
  6925.         desc=
  6926.         if [ -n "$variant" ]; then
  6927.             desc="$variant"
  6928.         fi
  6929.         if [ -n "$desc" ]; then
  6930.             desc=" (${desc})"
  6931.         fi
  6932.         preset=S      
  6933.         case $onboot in
  6934.         no|NO|No)
  6935.             preset=U       
  6936.             ;;
  6937.         esac
  6938.         # FIXME12: syslog does not respect the syntax.
  6939.         # set_val can not handle it.
  6940.         if [ "$daemon" = "syslog" ]; then
  6941.             preset=F
  6942.         fi
  6943.         echo "\"$daemon\" \"${hack}${desc}\" \"$preset\" \\"
  6944.     done
  6945. }
  6946.  
  6947. # Do_Setup_Daemon DAEMON {yes,no}
  6948. #
  6949. Do_Setup_Daemon()
  6950. {
  6951.     local dir_daemons=$DIR_TARGET/etc/sysconfig/daemons
  6952.  
  6953.     # FIXME12: syslog does not respect syntax. set_val can not handle it.
  6954.     if [ "$1" = "syslog" ]; then
  6955.         return 0
  6956.     fi
  6957.     if [ -f ${dir_daemons}/$1 ]; then
  6958.         set_val -f ${dir_daemons}/$1 ONBOOT $2
  6959.     else
  6960.         echo "ONBOOT=$2" > ${dir_daemons}/$1
  6961.     fi
  6962. }
  6963.  
  6964. Do_Setup_Daemons()
  6965. {
  6966.     local i
  6967.     local daemon
  6968.     local daemon_list="$1"
  6969.  
  6970.     # Do the necessary enable/disable modifications
  6971.     for i in $DIR_TARGET/etc/sysconfig/daemons/* ; do
  6972.         if [ ! -f $i ]; then continue ; fi
  6973.         daemon="`basename $i`"
  6974.         if [ -n "`echo "$daemon_list" | fgrep ":${daemon}:"`" ]; then
  6975.             Do_Setup_Daemon $daemon yes
  6976.         else
  6977.             Do_Setup_Daemon $daemon no
  6978.         fi
  6979.     done
  6980.  
  6981.     # Save ':'-separated list of daemons to be autostarted
  6982.     Do_Store CONF_DAEMON_SERVICES "$daemon_list"
  6983. }
  6984.  
  6985. Menu_Config_Daemons()
  6986. {
  6987.     local daemon
  6988.     local daemon_list
  6989.  
  6990.     Choose --multi --build Build_Daemons CONFIG_DAEMONS || return 1
  6991.  
  6992.     # The list of selected daemons for autostart is now in $FILE_TMP_ANSWER
  6993.     # and we store it as a ':'-separated list in the CONF_DAEMON_SERVICES
  6994.     # variable in /etc/system.cnf
  6995.     for daemon in `cat $FILE_TMP_ANSWER` ; do
  6996.         daemon_list="${daemon_list}:${daemon}"
  6997.     done
  6998.     if [ -n "$daemon_list" ]; then
  6999.         daemon_list="${daemon_list}:"
  7000.     fi
  7001.  
  7002.     Do_Setup_Daemons "$daemon_list"
  7003.     return 0
  7004. }
  7005.  
  7006. Get_MBR_dev()
  7007. {
  7008.     sysinfo --tag -C MBR --disk
  7009. }
  7010.  
  7011. Replace_MBR()
  7012. {
  7013.     local src=/boot/virgin.mbr
  7014.     local tgt=$1
  7015.  
  7016.     if [ ! -f $src ]; then
  7017.         Debug "could not find $src to replace $tgt"
  7018.         return 1
  7019.     fi
  7020.     dd if=$src of=$tgt bs=446 count=1 && {
  7021.         dd if=$src skip=510 bs=1 count=2 of=$tgt seek=510 && {
  7022.             Debug "sucessfully replaced $tgt with $src"
  7023.             return 0
  7024.         }
  7025.     }
  7026.     Debug "problems replacing $tgt"
  7027.     return 1
  7028. }
  7029.  
  7030. Do_Fix_MBR()
  7031. {
  7032.     local boot_sig_crc="b016f118"
  7033.     local real_sig_crc=
  7034.     local mbr_dev=
  7035.  
  7036.     mbr_dev="`Get_MBR_dev`"
  7037.     if [ -z "$mbr_dev" ]; then
  7038.         Debug "Get_MBR_dev returned nothing"
  7039.         return 1
  7040.     fi
  7041.     dd if=$mbr_dev bs=1 skip=510 count=2 of=/tmp/sig.mbr
  7042.     gzip -9 /tmp/sig.mbr 
  7043.     real_sig_crc="`gzip -lv /tmp/sig.mbr.gz | fgrep -v method | cut -d' ' -f 2`"
  7044.     Debug "real_sig_crc was <$real_sig_crc>"
  7045.     if [ -z "$real_sig_crc" ]; then
  7046.         Debug "real_sig_crc was empty"
  7047.         return 1
  7048.     fi
  7049.     if [ "$real_sig_crc" = "$boot_sig_crc" ]; then
  7050.         # for now be happy with that (simplified approach)
  7051.         return 0
  7052.     fi
  7053.     Debug "real_sig_crc != boot_sig_crc ==> replacing MBR"
  7054.     Replace_MBR $mbr_dev || return 1
  7055.     return 0
  7056. }
  7057.  
  7058. Menu_First_Config()
  7059. {
  7060.     local s
  7061.  
  7062.     if [ "`get_val -f /etc/lst.cnf CONF_COL_EDITION`" = "SBA" ]; then
  7063.         s=102
  7064.     else
  7065.         s=2
  7066.     fi
  7067.  
  7068.     Start_unconfigured_sh
  7069.  
  7070.     while [ 1 ]; do
  7071.         s="`do_calc $s - 1`"
  7072.         Debug "entering config stage $s ..."
  7073.         case $s in
  7074.         0|100)
  7075.             return 1
  7076.             ;;
  7077.         1)
  7078.             Menu_Config_Network || continue
  7079.             ;;
  7080.         101)
  7081.               Do_Setup_FQ_Name
  7082.             Do_Ifcfg lo up
  7083.             Do_Setup_Hosts
  7084.             if [ -z "`fgrep eth0 /proc/net/dev`" ]; then
  7085.                 Error "$dev ; :ERR_NO_DEVICE_AND_NO_MODULE:"
  7086.                 Do_Store CONF_eth0_STAT down
  7087.             else
  7088.                 Do_Store CONF_eth0_STAT up
  7089.                 Do_Store CONF_eth0_DEV "eth0"
  7090.                 Do_Store CONF_eth0_NAME "sba.local"
  7091.                 Do_Store CONF_eth0_IP "192.168.1.1"
  7092.                 Do_Store CONF_eth0_MASK "255.255.255.0"
  7093.                 Do_Store CONF_eth0_NET "192.168.1.0"
  7094.                 Do_Store CONF_eth0_BCAST "192.168.1.255"
  7095.                 Do_Store CONF_ROUTER1_IP "192.168.1.1"
  7096.                 Do_Setup_Hosts
  7097.                 Set_network
  7098.                 Set_ifcfg eth0
  7099.                 Do_Ifcfg eth0 up > $FILE_TMP_ERR 2>&1
  7100.                   Do_Ifcfg default up
  7101.             fi
  7102.               Do_Store CONF_DNS_SERVER1_IP "192.168.1.1"
  7103.             Do_Setup_DNS
  7104.             ;;
  7105.         2|102)
  7106.             Menu_Config_Timezone || continue
  7107.             ;;
  7108.         3)
  7109.             Menu_Config_Mouse || continue
  7110.             ;;
  7111.         4|103)
  7112.             Menu_Config_Printer || continue
  7113.             ;;
  7114.         5|104)
  7115.             Do_Set_Root_Password || continue
  7116.             ;;
  7117.         6|105)
  7118.             Do_Create_First_User || continue
  7119.             Fix_passwd
  7120.             ;;
  7121.         7)
  7122.             # omit this question if install source was CD
  7123.             if [ "`Get_Val CONF_INSTALL_MEDIUM`" != "cdrom" ]; then
  7124.                 Menu_Config_CD || continue
  7125.             fi
  7126.             ;;
  7127.         8|106)
  7128.             prep_use LILO
  7129.             while [ 1 ]; do
  7130.                 Menu_Config_LILO_HD && break
  7131.                 Msg ":ERR_BACKSTEP_NOT_POSSIBLE:"
  7132.             done
  7133.             Do_Fix_MBR
  7134.             ;;
  7135.         9)
  7136.             # configure daemons during first install
  7137.             Menu_Config_Daemons || continue
  7138.             ;;
  7139.         10)
  7140.             # configure X during first install
  7141.             if [ -f $DIR_TARGET/usr/X11R6/bin/startx ]; then
  7142.                 while [ 1 ]; do
  7143.                     Menu_Config_X_Server && break
  7144.                     Msg ":ERR_BACKSTEP_NOT_POSSIBLE:"
  7145.                 done
  7146.             fi
  7147.             ;;
  7148.         11)
  7149.             # store LISA configuration on floppy
  7150.             while [ 1 ]; do
  7151.                 Menu_Store_LISA_Config && break
  7152.                 Msg ":ERR_BACKSTEP_NOT_POSSIBLE:"
  7153.             done
  7154.             ;;
  7155.         12|107)
  7156.             # first configuration finished
  7157.             return 0
  7158.             ;;
  7159.         *)
  7160.             Panic "Menu_First_Config: should never get here."
  7161.             return 1
  7162.             ;;
  7163.         esac
  7164.         s="`do_calc $s + 2`"
  7165.     done
  7166. }
  7167.  
  7168. Do_Save_Package_Selection()
  7169. {
  7170.     if [ -f $FILE_PKGS_SEL ]; then
  7171.         cp -a $FILE_PKGS_SEL $DIR_TARGET/usr/lib/LST/pkgs.sel
  7172.     fi
  7173. }
  7174.  
  7175. Do_Store_LISA_Config()
  7176. {
  7177.   local was_mounted=
  7178.   local happy
  7179.   local i
  7180.  
  7181.   while [ 1 ]; do
  7182.       happy=true
  7183.       mount | fgrep 'on /floppy' > /dev/null && was_mounted=true
  7184.       umount /floppy >/dev/null 2>&1
  7185.     if [ $? -ne 0 ]; then
  7186.         echo "could not unmount" >> /dev/tty8
  7187.     fi
  7188.       Msg ":DO_INSERT_DOS_FLOPPY:" || return 1
  7189.       mount -t msdos /dev/fd0H1440 /floppy
  7190.       if [ $? -ne 0 ]; then
  7191.           Msg ":ERR_MOUNT_FLOPPY_FAILED:"
  7192.         return 1
  7193.       else
  7194.         touch /floppy/writable
  7195.         if [ $? -ne 0 ]; then
  7196.             # floppy write protected
  7197.             # FIXME
  7198.               # Msg ":ERR_MOUNT_FLOPPY_FAILED:"
  7199.               Msg "Write failed. The floppy is write protected."
  7200.             continue
  7201.         else
  7202.             rm -f /floppy/writable
  7203.         fi
  7204.     fi
  7205.     Info ":INFO_WAIT:"
  7206.     mkdir -p /floppy/etc
  7207.     mkdir -p /floppy/usr/lib/LST
  7208.     for i in /etc/lst.cnf /etc/system.cnf /usr/lib/LST/pkgs.sel ; do
  7209.         if [ -f $i ]; then
  7210.             cp -a $i /floppy/$i
  7211.             if [ $? -ne 0 ]; then
  7212.                 Debug "problems while copying $i"
  7213.                 happy=false
  7214.             fi
  7215.         else
  7216.             Debug "$i can not be copied: file not found"
  7217.             happy=false
  7218.         fi
  7219.     done
  7220.     sync
  7221.     sync
  7222.     umount /floppy >/dev/null 2>&1
  7223.     if [ "$happy" = "true" ]; then
  7224.         # FIXME
  7225.         # Msg ":INFO_WRITE_SUCCEEDED:" || continue
  7226.         Msg "The configuration has been saved successfully." || continue
  7227.         return 0
  7228.     fi
  7229.     Msg ":ERR_WRITE_FAILED:" || return 1
  7230.   done
  7231.   return 0
  7232. }
  7233.  
  7234. Menu_Store_LISA_Config()
  7235. {
  7236.     local defval
  7237.  
  7238.     if [ "$MODE_QUERY" = "auto" ]; then
  7239.         defval=n
  7240.     else
  7241.         defval=y
  7242.     fi
  7243.  
  7244.     while [ 1 ]; do
  7245.         Ask_Bool WRITE_CURRENT_CONFIG $defval || return 1
  7246.         case $ANSWER in
  7247.         0)
  7248.             Do_Store_LISA_Config || continue
  7249.             ;;
  7250.         esac
  7251.         return 0
  7252.     done
  7253. }
  7254.  
  7255. Set_LISA_CONF()
  7256. {
  7257.   mkdir -p $DIR_TARGET/etc
  7258.  
  7259.   # save lst setup
  7260.   cp -a /etc/lst.cnf $DIR_TARGET/etc
  7261.  
  7262.   # save system setup
  7263.   cp -a /etc/system.cnf $DIR_TARGET/etc
  7264.  
  7265.   # reset target and auto mode
  7266.   set_val -f $DIR_TARGET/etc/system.cnf DIR_TARGET "/"
  7267.   set_val -f $DIR_TARGET/etc/system.cnf MODE_QUERY "prompt"
  7268. }
  7269.  
  7270. Transfer_dev_symlinks()
  7271. {
  7272.   local i
  7273.  
  7274.   # save mouse/modem/cdrom symlinks
  7275.   for i in mouse modem cdrom ; do
  7276.     if [ -L /dev/$i ]; then
  7277.       rm -f $DIR_TARGET/dev/$i
  7278.       cp -a /dev/$i $DIR_TARGET/dev
  7279.     fi
  7280.   done
  7281. }
  7282.  
  7283. Set_message()
  7284. {
  7285.     conf_file=/boot/message
  7286.  
  7287.     # copy boot message
  7288.     if [ ! -f $DIR_TARGET$conf_file ]; then
  7289.         cp -a $conf_file $DIR_TARGET$conf_file
  7290.     fi
  7291. }
  7292.  
  7293. # FIXME: we have to rely that the linux symlink is there, otherwise 
  7294. #        we are running into a chicken and egg problem to determine
  7295. #        the future value of 'uname -r' and 'uname -v'. Now use
  7296. #     the value of the running kernel as fallback
  7297. Get_uname_r()
  7298. {
  7299.     local uname_r
  7300.  
  7301.     if [ -f $DIR_TARGET/usr/src/linux/include/linux/version.h ]; then
  7302.         fgrep UTS_RELEASE $DIR_TARGET/usr/src/linux/include/linux/version.h | cut -d'"' -f 2 > $FILE_TMP_VAL
  7303.         uname_r="`cat $FILE_TMP_VAL`"
  7304.     else
  7305.         uname_r="`uname -r`"
  7306.     fi
  7307.     Debug "Get_uname_r returns $uname_r"
  7308.     echo "$uname_r"
  7309. }
  7310.  
  7311. Get_uname_v()
  7312. {
  7313.     local uname_v
  7314.  
  7315.     if [ -f $DIR_TARGET/usr/src/linux/include/linux/compile.h ]; then
  7316.         fgrep UTS_VERSION $DIR_TARGET/usr/src/linux/include/linux/compile.h | cut -d'"' -f 2 > $FILE_TMP_VAL
  7317.         uname_v="`cat $FILE_TMP_VAL`"
  7318.     else
  7319.         uname_v="`uname -v`"
  7320.     fi
  7321.     Debug "Get_uname_v returns $uname_v"
  7322.     echo "$uname_v"
  7323. }
  7324.  
  7325. #
  7326. # prepare a valid initrd (all relative to PWD)
  7327. #
  7328. Prepare_Initrd()
  7329. {
  7330.   # FIXME12uname: because of the rebuild uname -v causes problems
  7331.   local uname_r="`Get_uname_r`"
  7332.   local uname_v="`Get_uname_v`"
  7333.   local mod_file="/etc/modules/${uname_r}/${uname_v}.rootfs"
  7334.   local driver
  7335.   local moddir
  7336.   local module
  7337.   local ans
  7338.  
  7339.   # create minimal directories
  7340.   mkdir -p bin dev etc/rc.d etc/modules/${uname_r} etc/modules/options lib/modules/${uname_r} sbin
  7341.  
  7342.   # create minimal devices
  7343.   mknod -m 644 dev/tty0 c 4 0
  7344.   mknod -m 644 dev/tty1 c 4 1
  7345.   ln -s tty0 dev/console
  7346.  
  7347.   # copy minimal libraries
  7348.   cp -a /lib/libc* lib
  7349.   cp -a /lib/ld.so* lib
  7350.   cp -a /etc/ld.so.conf etc
  7351.  
  7352.   # copy minimal binaries
  7353.   cp -a /bin/sh bin
  7354.   cp -a /sbin/insmod sbin
  7355.   cp -a /bin/uname bin
  7356.   cp -a /bin/cat bin
  7357.  
  7358.   for moddir in block cdrom fs ipv4 misc net pcmcia scsi sound ; do
  7359.     mkdir -p ./lib/modules/${uname_r}/$moddir
  7360.   done
  7361.  
  7362.   # copy rootfs module list and corresponding modules and params files
  7363.   if [ -f "$DIR_TARGET/$mod_file" ]; then
  7364.     cp -a "$DIR_TARGET/$mod_file" ./"$mod_file"
  7365.     cp -a "$DIR_TARGET/$mod_file" ./etc/modules/${uname_r}/rootfs
  7366.     # copy necessary modules
  7367.     for driver in `cat "$DIR_TARGET/$mod_file"` ; do
  7368.       for moddir in block cdrom fs ipv4 misc net pcmcia scsi sound ; do
  7369.         module=/lib/modules/${uname_r}/$moddir/${driver}.o
  7370.     # we use the modules from the target system
  7371.     if [ -f $DIR_TARGET/$module ]; then
  7372.       mkdir -p /lib/modules/${uname_r}/$moddir
  7373.       cp -a $DIR_TARGET/$module ./$module
  7374.       Debug "$module copied to initrd from target system"
  7375.     else
  7376.       Debug "did not find module $DIR_TARGET/$module to be copied to initrd"
  7377.     fi
  7378.       done
  7379.       if [ -s /etc/modules/options/$driver ]; then
  7380.         cp -a /etc/modules/options/$driver etc/modules/options
  7381.     Debug "/etc/modules/options/$driver copied to initrd"
  7382.       fi
  7383.     done
  7384.   else
  7385.     Debug "<$mod_file> not found"
  7386.   fi
  7387.  
  7388.   # copy module autoload routine
  7389.   cp -a /etc/rc.d/rc.rootfs etc/rc.d
  7390.  
  7391.   # this is used to trigger a initrd umount and freeramdisk in rc.boot
  7392.   touch free_initrd
  7393.  
  7394.   # create a very simple linuxrc
  7395.   echo '#!/bin/sh' > linuxrc
  7396.   echo "/bin/sh /etc/rc.d/rc.rootfs" >> linuxrc
  7397.   echo "exit 0" >> linuxrc
  7398.   chmod 755 linuxrc
  7399. }
  7400.  
  7401. #
  7402. # create compressed initrd image using the loop mount
  7403. #
  7404. Create_Initrd()
  7405. {
  7406.   local LoopFile=$DIR_TARGET/tmp/loopfile
  7407.   local LoopFileSize=2880
  7408.   local LoopMountPoint=$DIR_TARGET/mnt
  7409.   local InitrdImage=$DIR_TARGET/boot/initrd.gz
  7410.  
  7411.   Do_Clear_Screen
  7412.   echo "Preparing initrd..."
  7413.   echo
  7414.  
  7415.   prep_use LOOP
  7416.   prep_use PREPARE
  7417.  
  7418.   # load loop support
  7419.   Do_Load_Module --silent loop block
  7420.  
  7421.   # clear loopfile
  7422.   dd if=/dev/zero of=$LoopFile bs=1k count=$LoopFileSize
  7423.  
  7424.   # create loop device if necessary
  7425.   if [ ! -b /dev/loop0 ]; then
  7426.     mknod -m 666 /dev/loop0 b 7 0
  7427.   fi
  7428.  
  7429.   # prepare loop file for mount
  7430.   losetup /dev/loop0 $LoopFile
  7431.  
  7432.   # create filesystem on loopfile
  7433.   mke2fs /dev/loop0 $LoopFileSize
  7434.  
  7435.   echo
  7436.   echo "Please wait..."
  7437.  
  7438.   # mount loopfile as block device (needs mount >= 2.5k)
  7439.   mount -t ext2 /dev/loop0 $LoopMountPoint
  7440.  
  7441.   # create a minimal initrd for this system
  7442.   ( cd $LoopMountPoint ; Prepare_Initrd )
  7443.  
  7444.   # unmount it
  7445.   umount /dev/loop0
  7446.  
  7447.   # create compressed initrd from it
  7448.   dd if=/dev/loop0 bs=1k count=$LoopFileSize | gzip -9 > $InitrdImage
  7449.  
  7450.   # detach it
  7451.   losetup -d /dev/loop0
  7452.  
  7453.   # remove loopfile
  7454.   rm -f $LoopFile
  7455.  
  7456.   # unload loop support
  7457.   rmmod loop
  7458.  
  7459.   # FIXME: add it as default LILO entry
  7460.   # currently we trigger if a $DIR_TARGET/boot/initrd.gz is present
  7461.  
  7462.   end_use LOOP
  7463.   end_use PREPARE
  7464.  
  7465.   sleep 3
  7466. }
  7467.  
  7468. Is_SCSI_Root()
  7469. {
  7470.   local root_dev="`Get_Val CONF_INSTALL_ROOT`"
  7471.  
  7472.   echo "$root_dev" | fgrep "/dev/sd" > /dev/null && return 0
  7473.   return 1
  7474. }
  7475.  
  7476. # check if we use an ethercard
  7477. Is_Etherhost()
  7478. {
  7479.   cat /proc/net/dev | fgrep eth0 > /dev/null && return 0
  7480.   return 1
  7481. }
  7482.  
  7483. Set_initrd()
  7484. {
  7485.   local need_initrd=
  7486.  
  7487.   Is_SCSI_Root && need_initrd=true
  7488.   # Is_Etherhost && need_initrd=true
  7489.   if [ -n "$need_initrd" ]; then
  7490.     # we need a initrd
  7491.     Create_Initrd
  7492.   else
  7493.     # we don't need a initrd
  7494.     rm -fr $DIR_TARGET/initrd/*
  7495.   fi
  7496.   return 0
  7497. }
  7498.  
  7499. Set_modules_autoload()
  7500. {
  7501.   local uname_r="`Get_uname_r`"
  7502.   local uname_v="`Get_uname_v`"
  7503.   local confpath="/etc/modules/${uname_r}"
  7504.   local driver
  7505.   local mod_file
  7506.   local param_file
  7507.  
  7508.   # modules loaded by LISA were stored in this file
  7509.   local lisa_modules_file=/tmp/modules.initrd
  7510.   touch $lisa_modules_file
  7511.  
  7512.   # modules already handled will be stored in this file
  7513.   local handled_modules_file=$DIR_TARGET/tmp/modules.handled
  7514.   mkdir -p $DIR_TARGET/tmp
  7515.   rm -f $handled_modules_file
  7516.   touch $handled_modules_file
  7517.  
  7518.   # modules needed for the rootfs will be stored in this file
  7519.   # FIXME12uname: because of the rebuild uname -v causes problems
  7520.   local rootfs_modules_file="$DIR_TARGET$confpath/${uname_v}.rootfs"
  7521.   rm -f "$rootfs_modules_file"
  7522.   touch "$rootfs_modules_file"
  7523.  
  7524.   # modules needed for everything but the rootfs will be stored in this file
  7525.   # FIXME12uname: because of the rebuild uname -v causes problems
  7526.   local non_rootfs_modules_file="$DIR_TARGET$confpath/${uname_v}.default"
  7527.   mkdir -p $DIR_TARGET/etc/modules/options
  7528.   mkdir -p $DIR_TARGET$confpath
  7529.   rm -f "$non_rootfs_modules_file"
  7530.   touch "$non_rootfs_modules_file"
  7531.  
  7532.   # The list of modules to be autoloaded consists of 3 parts:
  7533.   # 1. modules loaded by LISA (during autoprobing and on user's request)
  7534.   local lisa_modules="`cat $lisa_modules_file`"
  7535.   # 2. modules that are loaded now (that we don't miss manually loaded modules)
  7536.   local loaded_modules="`cat /proc/modules | cut -d' ' -f 1`"
  7537.   # 3. modules that we want always to be loaded 
  7538.   local default_modules="sunrpc lockd fat msdos umsdos vfat parport parport_pc parport_probe soundcore soundlow 8390 scsi_mod sd_mod sr_mod st sg nfs isofs lp slhc slip ppp ipx"
  7539.  
  7540.   # The modules may be autoloaded in 2 steps:
  7541.   # 1. modules required to load the root filesystem thus loaded in the initrd
  7542.   #    (this is only necessary if ethercard used or rootfs on a SCSI device)
  7543.   local need_initrd=
  7544.   # 2. other modules 
  7545.  
  7546.   # check if rootfs on SCSI
  7547.   Is_SCSI_Root && need_initrd=true
  7548.  
  7549.   # check if we use an ethercard
  7550.   # FIXME: we don't support NFS mounted root at the moment
  7551.   # Is_Etherhost && need_initrd=true
  7552.  
  7553.   # store modules and their params in the appropriate autoload files
  7554.   for driver in $lisa_modules $loaded_modules $default_modules ; do
  7555.     if [ -n "`fgrep -x $driver "$handled_modules_file"`" ]; then
  7556.       Debug "'$driver' is already handled"
  7557.       continue
  7558.     fi
  7559.     echo "$driver" >> "$handled_modules_file"
  7560.     Debug "added '$driver' to '$handled_modules_file'"
  7561.     mod_file="$non_rootfs_modules_file"
  7562.     param_file="$DIR_TARGET/etc/modules/options/$driver"
  7563.     if [ -n "$need_initrd" ]; then
  7564.       # FIXME: this is a dumb check for scsi driver (should be done by sysinfo)
  7565.       if [ -f /lib/modules/`uname -r`/scsi/$driver.o ]; then
  7566.         mod_file="$rootfs_modules_file"
  7567.       fi
  7568.       # FIXME: this is a dumb check for ether driver (should be done by sysinfo)
  7569.       # FIXME: we don't support NFS mounted root at the moment
  7570.       #if [ -f /lib/modules/${uname_r}/net/$driver.o ]; then
  7571.       #  mod_file="$rootfs_modules_file"
  7572.       #fi
  7573.     fi
  7574.     echo "$driver" >> "$mod_file"
  7575.     Debug "added '$driver' to '$mod_file'"
  7576.     if [ -s /etc/modules/options/$driver ]; then
  7577.       Debug "added '`cat /etc/modules/$driver`' to '$param_file'"
  7578.       cp -a /etc/modules/options/$driver $param_file
  7579.     fi
  7580.   done
  7581. }
  7582.  
  7583. Set_etc_HOSTNAME()
  7584. {
  7585.     local conf_file=$DIR_TARGET/etc/HOSTNAME
  7586.     mkdir -p $DIR_TARGET/etc
  7587.     echo "`Get_Val CONF_FQ_HOSTNAME`" > $conf_file
  7588. }
  7589.  
  7590. Set_keyboard()
  7591. {
  7592.     local conf_file=$DIR_TARGET/etc/sysconfig/keyboard
  7593.  
  7594.     echo "KEYTABLE=`Get_Val CONF_KEYBOARD_MAP`" > $conf_file
  7595. }
  7596.  
  7597. Set_clock()
  7598. {
  7599.     local conf_file=$DIR_TARGET/etc/sysconfig/clock
  7600.     local timezone="`Get_Val CONF_TIMEZONE`"
  7601.     local zoneinfo_dir=/usr/share/zoneinfo
  7602.  
  7603.     mkdir -p $DIR_TARGET/etc/sysconfig
  7604.     if [ "`Get_Val CONF_KERNTZ_FLAG`" = "u" ]; then
  7605.         echo "CLOCKMODE=GMT" > $conf_file
  7606.     else
  7607.         echo "CLOCKMODE=LOCAL" > $conf_file
  7608.     fi
  7609.  
  7610.     if [ -z "$timezone" ]; then
  7611.         timezone=GMT
  7612.     fi
  7613.     if [ ! -d $DIR_TARGET$zoneinfo_dir ]; then
  7614.         zoneinfo_dir=/usr/lib/zoneinfo
  7615.     fi
  7616.     # fix symlink only if it's NOT pointing relative to /etc/localtime
  7617.     if [ -z "`ls -l ${DIR_TARGET}${zoneinfo_dir}/localtime | fgrep ' ../../../etc/localtime'`" ]; then
  7618.         ln -sf ../../../etc/localtime ${DIR_TARGET}${zoneinfo_dir}/localtime
  7619.     fi
  7620.     rm -f $DIR_TARGET/etc/localtime
  7621.     mkdir -p $DIR_TARGET/etc
  7622.     ln -sf ..${zoneinfo_dir}/$timezone $DIR_TARGET/etc/localtime
  7623. }
  7624.  
  7625. Set_pcmcia()
  7626. {
  7627.   local conf_file=$DIR_TARGET/etc/sysconfig/pcmcia
  7628.  
  7629.   # check if we used pcmcia during install
  7630.   # (in this case some modules were loaded from rc.S)
  7631.   if [ -n "`fgrep pcmcia_core /proc/modules`" ]; then
  7632.     echo "PCMCIA=yes" > $conf_file
  7633.     if [ -n "`fgrep i82365 /proc/modules`" ]; then
  7634.       echo "PCIC=i82365" >> $conf_file
  7635.     elif [ -n "`fgrep tcic /proc/modules`" ]; then
  7636.       echo "PCIC=tcic" >> $conf_file
  7637.     else
  7638.       # ??? shouldn't happpen
  7639.       echo "PCIC=" >> $conf_file
  7640.     fi
  7641.   else
  7642.     echo "PCMCIA=no" > $conf_file
  7643.     echo "PCIC=" >> $conf_file
  7644.   fi
  7645.   echo "OPTS=\"poll_interval=300\"" >> $conf_file
  7646. }
  7647.  
  7648. Set_network()
  7649. {
  7650.   local conf_file=$DIR_TARGET/etc/sysconfig/network
  7651.  
  7652.   mkdir -p $DIR_TARGET/etc/sysconfig
  7653.   echo "NETWORKING=yes" > $conf_file
  7654.   echo "HOSTNAME=`Get_Val CONF_FQ_HOSTNAME`" >> $conf_file
  7655.   echo "IF_LIST='lo eth tr sl ppp'" >> $conf_file
  7656. }
  7657.  
  7658. Set_ifcfg()
  7659. {
  7660.     local dev=$1
  7661.     local val=
  7662.     local conf_file=$DIR_TARGET/etc/sysconfig/network-scripts/ifcfg-${dev}
  7663.  
  7664.     mkdir -p $DIR_TARGET/etc/sysconfig/network-scripts
  7665.     echo '#!/bin/sh' > $conf_file
  7666.     case $dev in
  7667.     eth0|eth1)
  7668.         echo '#>>>Device type: ethernet' >> $conf_file
  7669.         ;;
  7670.     tr0)
  7671.         echo '#>>>Device type: token ring' >> $conf_file
  7672.         ;;
  7673.     plip0|plip1|plip2)
  7674.         echo '#>>>Device type: parallel line IP' >> $conf_file
  7675.         ;;
  7676.     esac
  7677.     echo '#>>>Variable declarations:' >> $conf_file
  7678.     echo "DEVICE=`Get_Val CONF_${dev}_DEV`" >> $conf_file
  7679.     echo "IPADDR=`Get_Val CONF_${dev}_IP`" >> $conf_file
  7680.     if [ -n "`Get_Val CONF_${dev}_REMOTE_IP`" ]; then
  7681.         echo "PTPADDR=`Get_Val CONF_${dev}_REMOTE_IP`" >> $conf_file
  7682.         if [ "`echo $dev | cut -c1-4`" = "plip" ]; then
  7683.             cat << EOF >> $conf_file
  7684. # for communication with DOS boxes turn activate
  7685. #IFOPTIONS="arp"
  7686. EOF
  7687.         fi
  7688.     fi
  7689.     echo "NETMASK=`Get_Val CONF_${dev}_MASK`" >> $conf_file
  7690.     echo "NETWORK=`Get_Val CONF_${dev}_NET`" >> $conf_file
  7691.     echo "BROADCAST=`Get_Val CONF_${dev}_BCAST`" >> $conf_file
  7692.     if [ "$dev" = "eth0" -o "`echo $dev | cut -c1-4`" = "plip" ]; then
  7693.         if [ -z "`Get_Val CONF_ROUTER1_IP`" ]; then
  7694.             echo "GATEWAY=none" >> $conf_file
  7695.         else
  7696.             echo "GATEWAY=`Get_Val CONF_ROUTER1_IP`" >> $conf_file
  7697.         fi
  7698.     else
  7699.         echo "GATEWAY=none" >> $conf_file
  7700.     fi
  7701.     if [ "`Get_Val CONF_${dev}_STAT`" = "up" ]; then
  7702.         echo "ONBOOT=yes" >> $conf_file
  7703.     else
  7704.         echo "ONBOOT=no" >> $conf_file
  7705.     fi
  7706.     echo '#>>>End variable declarations' >> $conf_file
  7707.     chmod 755 $conf_file
  7708. }
  7709.  
  7710. Fix_basename()
  7711. {
  7712.   # FIXME: (ugly) overwrite the a.out binary with the ELF version
  7713.   if [ -f $DIR_TARGET/usr/bin/basename ]; then
  7714.     cp -af $DIR_TARGET/usr/bin/basename $DIR_TARGET/bin/basename
  7715.   else
  7716.     if [ ! -f $DIR_TARGET/bin/basename ]; then
  7717.       if [ -f /bin/basename ]; then
  7718.         cp -af /bin/basename $DIR_TARGET/bin/basename
  7719.       fi
  7720.     fi
  7721.   fi
  7722. }
  7723.  
  7724. Fix_Obsolete_Progs()
  7725. {
  7726.   local i
  7727.  
  7728.   Fix_basename
  7729.  
  7730.   # remove obsolete progies from /root
  7731.   for i in floppy README bin/rpmq ; do
  7732.     rm -fr $DIR_TARGET/$i
  7733.   done
  7734.   # remove obsolete libs from /root
  7735.   rm -f $DIR_TARGET/lib/libc.so.4
  7736.   rm -f $DIR_TARGET/lib/libc.so.4.5.24
  7737. }
  7738.  
  7739. Fix_conf_getty()
  7740. {
  7741.   local conf_file=/etc/conf.getty
  7742.   
  7743.   # disable getty's clear-screen behaviour
  7744.   if [ ! -f $DIR_TARGET$conf_file ]; then
  7745.     echo "CLEAR=NO" > $DIR_TARGET$conf_file
  7746.     chmod 644 $DIR_TARGET$conf_file
  7747.   fi
  7748. }
  7749.  
  7750. Fix_rc_sysinit()
  7751. {
  7752.   local conf_file=/etc/rc.d/rc.sysinit
  7753.  
  7754.   # autoload the default modules
  7755.   if [ -z "`fgrep rc.modules $DIR_TARGET$conf_file`" ]; then
  7756.     cat << 'EOF' >> $DIR_TARGET$conf_file
  7757.  
  7758. # Autoload the default modules
  7759. if [ -f /etc/rc.d/rc.modules ]; then
  7760.     /etc/rc.d/rc.modules
  7761. fi
  7762.  
  7763. EOF
  7764.   fi
  7765. }
  7766.  
  7767.  
  7768. # try to detect broken insmod by gzip's CRC and replace it.
  7769. #
  7770. Fix_Broken_Insmod()
  7771. {
  7772.   local badcsum
  7773.  
  7774.   if [ -f $DIR_TARGET/sbin/insmod ]; then
  7775.     cp -a $DIR_TARGET/sbin/insmod $DIR_TARGET/tmp/insmod
  7776.     gzip -9f $DIR_TARGET/tmp/insmod
  7777.     badcsum="`gzip -lv $DIR_TARGET/tmp/insmod.gz | fgrep insmod | cut -c 7-14`"
  7778.     if [ "$badcsum" = "51763471" -o "$badcsum" = "2eca023d" ]; then
  7779.       Debug "broken insmod detected and replaced"
  7780.       cp -a /sbin/insmod $DIR_TARGET/sbin/insmod
  7781.     else
  7782.       Debug "CRC of insmod doesn't match broken one"
  7783.     fi
  7784.     rm -f $DIR_TARGET/tmp/insmod.gz
  7785.   else
  7786.     Debug "no insmod found"
  7787.   fi
  7788. }
  7789.  
  7790. # fix /etc/fstab
  7791. #
  7792. Fix_etc_fstab()
  7793. {
  7794.   local conf_file=$DIR_TARGET/etc/fstab
  7795.   local cd_dev="`Get_Val CONF_CD1_DEV`"
  7796.  
  7797.   # add floppy and cdrom entries in fstab
  7798.   mkdir -p $DIR_TARGET/mnt/floppy
  7799.   mkdir -p $DIR_TARGET/mnt/cdrom
  7800.   cat << 'EOF' >> $conf_file
  7801. #
  7802. /dev/fd0 /mnt/floppy msdos defaults,user,noauto 0 0
  7803. #
  7804. EOF
  7805.   if [ -n "$cd_dev" ]; then
  7806.     echo "$cd_dev /mnt/cdrom iso9660 ro,user,noauto 0 0" >> $conf_file
  7807.   fi
  7808. }
  7809.  
  7810. Fix_ldconfig()
  7811. {
  7812.   export PATH="/bin:/sbin:/usr/bin:/usr/sbin:/usr/X11R6/bin"
  7813.  
  7814.   if [ ! -f /sbin/ldconfig ]; then
  7815.     ln -s $DIR_TARGET/sbin/ldconfig /sbin/ldconfig
  7816.     Debug "creating symlink for /sbin/ldconfig"
  7817.   fi
  7818.   #Debug "running 'chroot $DIR_TARGET ldconfig -X'"
  7819.   #chroot $DIR_TARGET ldconfig -X
  7820.   Debug "running 'chroot $DIR_TARGET sbin/ldconfig'"
  7821.   ( cd $DIR_TARGET; chroot $DIR_TARGET sbin/ldconfig ) > $DIR_TARGET/tmp/ldconfig.out 2>&1
  7822. }
  7823.  
  7824. Fix_lilo()
  7825. {
  7826.     local i
  7827.  
  7828.     prep_use LILO
  7829.  
  7830.     for i in /sbin/lilo /sbin/activate /boot/boot.b /boot/message /boot/any_b.b /boot/any_d.b /boot/os2_d.b /boot/chain.b /etc/lilo.conf.in ; do
  7831.         if [ -f $i.gz ]; then
  7832.             gzip -df $i
  7833.         fi
  7834.         if [ "$CND10_MODE" = "true" ]; then
  7835.             if [ -f $i ]; then
  7836.                 cp -a $i $DIR_TARGET$i
  7837.             fi
  7838.         fi
  7839.     done
  7840. }
  7841.  
  7842. Fix_procps()
  7843. {
  7844.   local i
  7845.  
  7846.   for i in /bin/ps /bin/kill ; do
  7847.     if [ -f $i ]; then
  7848.       cp -a $i $DIR_TARGET$i
  7849.     fi
  7850.   done
  7851. }
  7852.  
  7853. Set_Resolver()
  7854. {
  7855.   local i
  7856.  
  7857.   for i in $FILE_ETC_HOSTS $FILE_ETC_RESOLV_CONF ; do
  7858.     if [ -f $i ]; then
  7859.       cp -a $i $DIR_TARGET$i
  7860.     fi
  7861.   done
  7862. }
  7863.  
  7864. Fix_freeramdisk()
  7865. {
  7866.   if [ "$CND10_MODE" = "true" ]; then
  7867.     # make sure the initrd will be saved and freeramdisk called
  7868.     if [ -f /etc/rc.d/rc.free ]; then
  7869.       cp -a /etc/rc.d/rc.free $DIR_TARGET/etc/rc.d/rc.free
  7870.       cat << EOF >> $DIR_TARGET/etc/rc.d/rc.local
  7871. if [ -x /etc/rc.d/rc.free ]; then
  7872. /etc/rc.d/rc.free
  7873. fi
  7874. EOF
  7875.     fi
  7876.     if [ ! -f /root/bin/freeramdisk ]; then
  7877.       if [ -f /bin/freeramdisk.gz ]; then
  7878.     cp -a /bin/freeramdisk.gz /root/bin
  7879.     gzip -df /root/bin/freeramdisk.gz
  7880.       fi
  7881.     fi
  7882.   fi
  7883. }
  7884.  
  7885. Fix_Missing_Root()
  7886. {
  7887.   mkdir -p $DIR_TARGET/root
  7888. }
  7889.  
  7890. # FIXME: obsolete now?
  7891. Fix_faked_lib_versions()
  7892. {
  7893.   if [ ! -f $DIR_TARGET/usr/lib/libdb.so.2 ]; then
  7894.     ln -s libdb.so.1 $DIR_TARGET/usr/lib/libdb.so.2
  7895.     Debug "Fixing libdb symlink"
  7896.   fi
  7897. }
  7898.  
  7899. Fix_news()
  7900. {
  7901.   echo "IDENT=news-system" > $DIR_TARGET/etc/sysconfig/daemons/news
  7902.   echo "ONBOOT=no" >> $DIR_TARGET/etc/sysconfig/daemons/news
  7903.   chmod 644 $DIR_TARGET/etc/sysconfig/daemons/news
  7904. }
  7905.  
  7906. # FIXME: is now in skeleton.cgz but still necessary for LST 2.2 install
  7907. Fix_daemons()
  7908. {
  7909.   mkdir -p $DIR_TARGET/etc/sysconfig/daemons
  7910. }
  7911.  
  7912.  
  7913. Fix_3c59x()
  7914. {
  7915.   if [ -f /lib/modules/2.0.21/net/3c59x.o.gz ]; then
  7916.     gzip -df /lib/modules/2.0.21/net/3c59x.o.gz
  7917.   fi
  7918.   if [ -f /lib/modules/2.0.21/net/3c59x.o ]; then
  7919.     cp -af /lib/modules/2.0.21/net/3c59x.o $DIR_TARGET/lib/modules/2.0.21/net
  7920.   fi
  7921. }
  7922.  
  7923. Fix_DEV()
  7924. {
  7925.     if [ ! -b $DIR_TARGET/dev/cdu31a ]; then
  7926.         if [ -b $DIR_TARGET/dev/sonycd ]; then
  7927.             cp -a $DIR_TARGET/dev/sonycd $DIR_TARGET/dev/cdu31a
  7928.         fi
  7929.     fi
  7930. }
  7931.  
  7932. Fix_runlevel()
  7933. {
  7934.     # With COL 2.2 the default runlevel is 5, but with the lisa install
  7935.     # X is not configured yet, so we must set the default runlevel to 3
  7936.     sed 's/^id:5:initdefault:/id:3:initdefault:/' $DIR_TARGET/etc/inittab > $DIR_TARGET/etc/inittab.tmp
  7937.     mv $DIR_TARGET/etc/inittab.tmp $DIR_TARGET/etc/inittab
  7938.     chmod 644 $DIR_TARGET/etc/inittab
  7939. }
  7940.  
  7941. Fix_shadow22()
  7942. {
  7943.     sed 's/:0::7:7::/:0:365:7:7::/' $DIR_TARGET/etc/shadow > $DIR_TARGET/etc/shadow.tmp
  7944.     mv $DIR_TARGET/etc/shadow.tmp $DIR_TARGET/etc/shadow
  7945.     chmod 600 $DIR_TARGET/etc/shadow
  7946. }
  7947.  
  7948. Do_Fixes_After_First_Config()
  7949. {
  7950.     Info ":INFO_COPYING_FILES_TO_TARGET:"
  7951.     Set_LISA_CONF
  7952.     Transfer_dev_symlinks
  7953.     Fix_Missing_Root
  7954.     Fix_Broken_Insmod
  7955.     mkdir -p /etc/sysconfig
  7956.     mkdir -p /etc/sysconfig/network-scripts
  7957.     mkdir -p /etc/rc.d/init.d
  7958.     Set_etc_HOSTNAME
  7959.     Set_keyboard
  7960.     Set_pcmcia
  7961.     Set_network
  7962.     Set_ifcfg eth0
  7963.     Set_ifcfg tr0
  7964.     # Fix_conf_getty
  7965.     Fix_etc_fstab
  7966.     Set_Resolver
  7967.     Fix_faked_lib_versions
  7968.     Fix_Obsolete_Progs
  7969.     Fix_ldconfig
  7970.     if [ "$CND10_MODE" = "true" ]; then
  7971.         Fix_freeramdisk
  7972.         Fix_rc_sysinit
  7973.         Fix_procps
  7974.     fi
  7975.     Fix_news
  7976.     Fix_3c59x
  7977.     Fix_DEV
  7978.     Do_Setup_teTeX
  7979.     Do_Setup_locate
  7980.     Fix_tmp_area
  7981.     Fix_uucp
  7982.     Fix_runlevel
  7983.     Fix_shadow22
  7984.     Finish_unconfigured_sh
  7985. }
  7986.  
  7987.  
  7988. Fix_tmp_area()
  7989. {
  7990.   mkdir -p $DIR_TARGET/tmp
  7991.   chmod 1777 $DIR_TARGET/tmp
  7992.   Debug "Fixing mode of tmp area"
  7993. }
  7994.  
  7995. Create_fsstnd()
  7996. {
  7997.   # FIXME: should be created by a fsstnd pkg
  7998.   mkdir -p $DIR_TARGET/tmp
  7999.   chmod 1777 $DIR_TARGET/tmp
  8000.   mkdir -p $DIR_TARGET/boot
  8001.   mkdir -p $DIR_TARGET/etc
  8002.   mkdir -p $DIR_TARGET/mnt
  8003.   mkdir -p $DIR_TARGET/usr
  8004.   #( cd $DIR_TARGET/usr ; ln -sf ../var/spool spool )
  8005.   #mkdir -p $DIR_TARGET/var/spool/lpd
  8006.   #mkdir -p $DIR_TARGET/var/spool/mail
  8007.   #mkdir -p $DIR_TARGET/var/spool/news
  8008.   #mkdir -p $DIR_TARGET/var/spool/uucp
  8009. }
  8010.  
  8011. Transfer_LISA()
  8012. {
  8013.   local i
  8014.   local binaries_from_floppy
  8015.  
  8016.   if [ "$CND10_MODE" = "true" ]; then
  8017.     binaries_from_floppy="box build_menu db_printf do_calc do_echo do_netcalc do_quote filesize get_info get_key get_val hilfe lisa prep_use set_val sysinfo rpmq"
  8018.   else
  8019.     binaries_from_floppy="filesize hilfe lisa prep_use"
  8020.   fi
  8021.  
  8022.  
  8023.   # init LISA tmp area
  8024.   mkdir -p $DIR_TARGET/tmp/LST
  8025.   chmod 1777 $DIR_TARGET/tmp
  8026.  
  8027.   # init LISA install area
  8028.   # be backward compatible to old LST install directory
  8029.   mkdir -p $DIR_TARGET/var/lib/LST
  8030.   mkdir -p $DIR_TARGET/var/lib/LST/log
  8031.   mkdir -p $DIR_TARGET/var/lib/LST/analyse
  8032.   rm -fr $DIR_TARGET/install
  8033.   ln -sf var/lib/LST $DIR_TARGET/install
  8034.   echo "$CONF_LST_VERSION" > $DIR_TARGET/install/BASEVERSION
  8035.   if [ -d /var/lib/LST ]; then
  8036.     cp -aR /var/lib/LST $DIR_TARGET/var/lib
  8037.   fi
  8038.  
  8039.   # copy LISA doc area
  8040.   mkdir -p $DIR_TARGET/usr/doc/LST
  8041.   cp -aR /floppy/usr/doc/LST/* /usr/doc/LST/* /source/doc/LST/* $DIR_TARGET/usr/doc/LST
  8042.   gzip -df $DIR_TARGET/usr/doc/LST/*.gz
  8043.   if [ "$INSTALL_MODE" = "LST" ]; then
  8044.     # to make sure they are read ;-)
  8045.     for i in COPYING CREDITS README.1st ; do
  8046.       if [ -f $DIR_TARGET/usr/doc/LST/$i ]; then
  8047.         ln -s usr/doc/LST/$i $DIR_TARGET/$i
  8048.       fi
  8049.     done
  8050.   fi
  8051.  
  8052.   # copy LISA lib area
  8053.   mkdir -p $DIR_TARGET/usr/lib/LST
  8054.   cp -a /usr/lib/LST/smarties $DIR_TARGET/usr/lib/LST
  8055.   cp -a /usr/lib/LST/IDENTIFY $DIR_TARGET/usr/lib/LST/IDENTIFY.root
  8056.   if [ -f /floppy/IDENTIFY ]; then
  8057.     cp -a /floppy/IDENTIFY $DIR_TARGET/usr/lib/LST/IDENTIFY.boot
  8058.   fi
  8059.   echo "`uname -a`" > $DIR_TARGET/usr/lib/LST/IDENTIFY.kernel
  8060.   for i in libLSTall meta.db pkgs.db pkgs.idx ; do
  8061.     if [ -f /usr/lib/LST/$i.gz ]; then
  8062.       cp -a /usr/lib/LST/$i.gz $DIR_TARGET/usr/lib/LST/$i.gz
  8063.       gzip -df $DIR_TARGET/usr/lib/LST/$i.gz
  8064.     elif [ -f /usr/lib/LST/$i ]; then
  8065.       cp -a /usr/lib/LST/$i $DIR_TARGET/usr/lib/LST/$i
  8066.     fi
  8067.   done
  8068.   cp -a /usr/lib/LST/libLSTtext $DIR_TARGET/usr/lib/LST/libLSTtext
  8069.  
  8070.   # copy LISA binary files from floppy to target
  8071.   mkdir -p $DIR_TARGET/bin
  8072.   # FIXME: no binaries at all should be copied from the install floppy
  8073.   for i in $binaries_from_floppy ; do
  8074.     if [ -f /bin/$i.gz ]; then
  8075.       cp -a /bin/$i.gz $DIR_TARGET/bin
  8076.       gzip -df $DIR_TARGET/bin/$i.gz
  8077.     elif [ -f /bin/$i ]; then
  8078.       cp -a /bin/$i $DIR_TARGET/bin
  8079.     fi
  8080.   done
  8081.   ( cd $DIR_TARGET/bin ; ln -sf prep_use end_use )
  8082.   ( cd $DIR_TARGET/bin ; ln -sf prep_use not_use )
  8083.   ( cd $DIR_TARGET/bin ; ln -sf prep_use show_use )
  8084.   ( cd $DIR_TARGET/bin ; ln -sf lisa sysinstall )
  8085.   ( cd $DIR_TARGET/bin ; ln -sf lisa syssetup )
  8086.   ( cd $DIR_TARGET/bin ; ln -sf lisa netsetup )
  8087.  
  8088.   # copy LISA config files
  8089.   Set_LISA_CONF
  8090. }
  8091.  
  8092. Transfer_RPM()
  8093. {
  8094.   # init RPM area
  8095.   mkdir -p $DIR_TARGET/var/lib/rpm
  8096.   mkdir -p /var/lib
  8097.   ln -sf $DIR_TARGET/var/lib/rpm /var/lib/rpm
  8098. }
  8099.  
  8100. Transfer_kernel()
  8101. {
  8102.   local i
  8103.   local kernel
  8104.  
  8105.   # copy kernel
  8106.   for i in $DIR_TARGET/floppy/vmlinuz* ; do
  8107.     if [ -f $i ]; then
  8108.       kernel=`basename $i`
  8109.       ln -f $i $DIR_TARGET/$kernel
  8110.     fi
  8111.   done
  8112.   # copy WHATSIN files
  8113.   mkdir -p $DIR_TARGET/boot
  8114.   for i in $DIR_TARGET/floppy/boot/WHATSIN* ; do
  8115.     if [ -f $i ]; then
  8116.       kernel=`basename $i`
  8117.       ln -f $i $DIR_TARGET/boot/$kernel
  8118.     fi
  8119.   done
  8120. }
  8121.  
  8122. Transfer_modules()
  8123. {
  8124.   local i
  8125.  
  8126.   # copy modules
  8127.   mkdir -p $DIR_TARGET/lib/modules
  8128.   cp -aR /floppy/lib/modules/* /lib/modules/* $DIR_TARGET/lib/modules
  8129.   for i in $DIR_TARGET/lib/modules/`uname -r`/*/*.o.gz ; do
  8130.     if [ -f $i ]; then
  8131.       gzip -df $i
  8132.     fi
  8133.   done
  8134. }
  8135.  
  8136. Delete_unused_modules()
  8137. {
  8138.     local i
  8139.     local modpath=/lib/modules/`uname -r`
  8140.  
  8141.     for i in $modpath/*/*.gz ; do
  8142.         rm -f $i
  8143.     done
  8144. }
  8145.  
  8146. Do_Switch_Log_Area()
  8147. {
  8148.     Do_Log -f $FILE_LOG_HISTORY "`date` $LOGNAME: Moving log area to $DIR_TARGET"
  8149.     mkdir -p $DIR_TARGET/var/adm
  8150.     cp -aR /var/adm/LST $DIR_TARGET/var/adm
  8151.     rm -fr /var/adm/LST
  8152.     ln -s $DIR_TARGET/var/adm/LST /var/adm/LST
  8153. }
  8154.  
  8155. Transfer_root_floppy()
  8156. {
  8157.     local i
  8158.     local kernel=
  8159.     local prefix=
  8160.  
  8161.     # copy LILO files
  8162.     mkdir -p $DIR_TARGET/floppy/boot
  8163.     for i in any_b.b any_d.b boot.b chain.b message os2_d.b ; do
  8164.         if [ -f /boot/$i ]; then
  8165.             cp -a /boot/$i $DIR_TARGET/floppy/boot
  8166.         fi
  8167.         if [ -f /floppy/boot/$i ]; then
  8168.             cp -a /floppy/boot/$i $DIR_TARGET/floppy/boot
  8169.         fi
  8170.     done
  8171.  
  8172.     mkdir -p $DIR_TARGET/floppy/sbin
  8173.     for i in activate lilo sysinstall mkfs.minix ; do
  8174.         if [ -f /sbin/$i.gz ]; then
  8175.             cp -a /sbin/$i.gz $DIR_TARGET/floppy/sbin
  8176.             gunzip -f $DIR_TARGET/floppy/sbin/$i.gz
  8177.         fi
  8178.     done
  8179.  
  8180.     mkdir -p $DIR_TARGET/floppy/etc
  8181.     if [ -f /etc/lilo.conf.in ]; then
  8182.         cp -a /etc/lilo.conf.in $DIR_TARGET/floppy/etc/lilo.conf
  8183.     fi
  8184.  
  8185.     # copy kernel
  8186.     for i in /vmlinuz* /floppy/vmlinuz* ; do
  8187.         if [ -f $i ]; then
  8188.             kernel=`basename $i`
  8189.             cp -a $i $DIR_TARGET/floppy/$kernel
  8190.             rdev $DIR_TARGET/floppy/$kernel $CONF_INSTALL_ROOT
  8191.             rdev -r $DIR_TARGET/floppy/$kernel 0
  8192.             rdev -R $DIR_TARGET/floppy/$kernel 1
  8193.             if [ "$DIR_TARGET" = "/root/linux" ]; then
  8194.                 rdev -R $DIR_TARGET/floppy/$kernel 0
  8195.             fi
  8196.         fi
  8197.     done
  8198.  
  8199.     if [ -f /boot/WHATSIN* ]; then
  8200.         cp -a /boot/WHATSIN* $DIR_TARGET/floppy/boot
  8201.     fi
  8202.     if [ -f /floppy/boot/WHATSIN* ]; then
  8203.         cp -a /floppy/boot/WHATSIN* $DIR_TARGET/floppy/boot
  8204.     fi
  8205.  
  8206.     # creating device files
  8207.     mkdir -p $DIR_TARGET/floppy/dev
  8208.     prefix=$DIR_TARGET/floppy/dev/
  8209.     mknod -m 644 ${prefix}fd0 b 2 0
  8210.     mknod -m 644 ${prefix}fd0h1200 b 2 8
  8211.     mknod -m 644 ${prefix}fd0H1440 b 2 28
  8212.     mknod -m 644 ${prefix}fd1 b 2 1
  8213.     mknod -m 644 ${prefix}fd1h1200 b 2 9
  8214.     mknod -m 644 ${prefix}fd1H1440 b 2 29
  8215.     # chgrp root.disk ${prefix}fd*
  8216. }
  8217.  
  8218. Fix_apache()
  8219. {
  8220.     # apache-httpd version 1.1.1-10 is broken and needs symlinks
  8221.     if [ -n "`fgrep apache-httpd $FILE_PKGS_DATA | fgrep '1.1.1-10'`" ]; then
  8222.         Debug "fixing broken apache-httpd-1.1.1-10 package..."
  8223.         mkdir -p $DIR_TARGET/home/httpd
  8224.         ln -s apache/html $DIR_TARGET/home/httpd/html
  8225.         ln -s apache/cgi-bin $DIR_TARGET/home/httpd/cgi-bin
  8226.         ln -s apache/icons $DIR_TARGET/home/httpd/icons
  8227.     fi
  8228. }
  8229.  
  8230. Fix_useradd()
  8231. {
  8232.     # lisa-2.2-3 contains a broken useradd (creates "*" passwd entries)
  8233.     if [ -n "`fgrep lisa $FILE_PKGS_DATA | fgrep '2.2-3'`" ]; then
  8234.         if [ -r /usr/sbin/useradd.ELF.gz ]; then
  8235.             Debug "fixing broken lisa-2.2-3 package..."
  8236.             cp -af /usr/sbin/useradd.ELF.gz $DIR_TARGET/usr/sbin/useradd.gz
  8237.             gzip -df $DIR_TARGET/usr/sbin/useradd.gz
  8238.             chmod 755 $DIR_TARGET/usr/sbin/useradd
  8239.         fi
  8240.     fi
  8241. }
  8242.  
  8243. Fix_log_permissions()
  8244. {
  8245.     touch $DIR_TARGET/var/log/messages
  8246.     chmod 600 $DIR_TARGET/var/log/messages
  8247.     touch $DIR_TARGET/var/log/secure
  8248.     chmod 600 $DIR_TARGET/var/log/secure
  8249. }
  8250.  
  8251. Fix_rc_modules()
  8252. {
  8253.     sed '/^    insmod/s/\"//g' < $DIR_TARGET/etc/rc.d/rc.modules > $DIR_TARGET/etc/rc.d/rc.modules.tmp
  8254.     chmod 755 $DIR_TARGET/etc/rc.d/rc.modules.tmp
  8255.     mv $DIR_TARGET/etc/rc.d/rc.modules.tmp $DIR_TARGET/etc/rc.d/rc.modules
  8256. }
  8257.  
  8258. Do_Init_Target()
  8259. {
  8260.     local i
  8261.     local kernel=
  8262.     local prefix=
  8263.  
  8264.     Info ":INFO_COPYING_FILES_TO_TARGET:"
  8265.     Create_fsstnd
  8266.     Transfer_LISA
  8267.     Transfer_RPM
  8268.     Transfer_root_floppy
  8269.     Transfer_kernel
  8270.     Transfer_modules
  8271.     Set_modules_autoload
  8272.     Fix_12_Alpha target_mounted
  8273.     Set_initrd
  8274.     # FIXME: for debugging only
  8275.     # trigger a copy of the initrd we used for install under /var/tmp/initrd
  8276.     # touch /save_initrd
  8277.     # trigger a initrd umount and freeramdisk in rc.boot
  8278.     touch /free_initrd
  8279.     Set_message
  8280.     Fix_lilo
  8281.     Fix_daemons
  8282.     Fix_apache
  8283.     # FIXME: need better method to find initrd
  8284.     if [ "`uname -r`" != "1.2.13" ]; then
  8285.         mkdir -p $DIR_TARGET/initrd
  8286.         Set_Real_Root $CONF_INSTALL_ROOT
  8287.     fi
  8288.     # this is to support RPM 2.2.x
  8289.     mkdir -p $DIR_TARGET/etc
  8290. #    if [ "$DIR_TARGET" != "/" ]; then
  8291. #        cp -a /etc/passwd $DIR_TARGET/etc/passwd
  8292. #        cp -a /etc/group $DIR_TARGET/etc/group
  8293. #        # we bring a rpmrc for 2.2 with us on the floppy
  8294. #        # check if we have for newer ones
  8295. #        if [ -f /source/lib/rpmrc-2.5 ]; then
  8296. #            ln -s /source/lib/rpmrc-2.5 /usr/lib/rpmrc-2.5
  8297. #        elif [ -f /source/lib/rpmrc-2.4 ]; then
  8298. #            ln -s /source/lib/rpmrc-2.4 /usr/lib/rpmrc-2.4
  8299. #        fi
  8300. #    fi
  8301.     ROOT_INITIALIZED=1
  8302.     return 0
  8303. }
  8304.  
  8305. Fix_i386_RPMS()
  8306. {
  8307.     if [ "$INSTALL_MODE" != "OpenLinux" ]; then
  8308.         mkdir -p $DIR_TARGET/usr/src/redhat/RPMS/i386
  8309.     fi
  8310. }
  8311.  
  8312. Fix_SuperProbe()
  8313. {
  8314.     # security fix
  8315.     chmod -s $DIR_TARGET/usr/X11R6/bin/SuperProbe
  8316. }
  8317.  
  8318. Fix_root_dotfiles()
  8319. {
  8320.     mkdir -p $DIR_TARGET/root
  8321.     cp -aR $DIR_TARGET/etc/skel/.??* $DIR_TARGET/root
  8322. }
  8323.  
  8324. Fix_etc_login_defs()
  8325. {
  8326.     if [ -f $DIR_TARGET/etc/login.defs ]; then
  8327.         sed 's/^HOME        \/home/HOME        \/home\/%s/' $DIR_TARGET/etc/login.defs > $DIR_TARGET/etc/login.defs.tmp
  8328.         mv $DIR_TARGET/etc/login.defs.tmp $DIR_TARGET/etc/login.defs
  8329.         chmod 640 $DIR_TARGET/etc/login.defs
  8330.     fi
  8331. }
  8332.  
  8333. Fix_usr_info_dir_gz()
  8334. {
  8335.     # this file is not necessary and makes xeamcs really unhappy, so remove it
  8336.     if [ -f $DIR_TARGET/usr/info/dir.gz ]; then
  8337.         rm -f $DIR_TARGET/usr/info/dir.gz
  8338.     fi
  8339. }
  8340.  
  8341. Do_Fixes_After_Pkg_Install()
  8342. {
  8343.     Fix_sendmail_start
  8344.     Fix_httpd_start
  8345.     Fix_i386_RPMS
  8346.     Fix_SuperProbe
  8347.     Fix_rc_modules
  8348.     Fix_useradd
  8349.     Fix_log_permissions
  8350.     Fix_root_dotfiles
  8351.     Fix_etc_login_defs
  8352.     Fix_usr_info_dir_gz
  8353. }
  8354.  
  8355. # libLSTmodule - module handling library shared between several scripts
  8356. #
  8357. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  8358. #
  8359.  
  8360. Show_Kernel_Whatsin()
  8361. {
  8362.     if [ ! -f $1 ]; then
  8363.         Error "$1: file not found"
  8364.         return 1
  8365.     fi
  8366.     Browse2 $1 KERNEL_WHATSIN
  8367.     return 0
  8368. }
  8369.  
  8370. Menu_Config_Kernel()
  8371. {
  8372.     local item
  8373.  
  8374.     # "CREATE" ":MENU_CREATE_KERNEL:"
  8375.  
  8376.     while [ 1 ]; do
  8377.         $CMD_BOX --help ":MENU_CONFIG_KERNEL_HELP:" \
  8378. --default "$item" \
  8379. --title ":MENU_CONFIG_KERNEL_TITLE:" \
  8380. --menu ":MENU_CONFIG_KERNEL_TEXT:" \
  8381. "WHATSIN" ":INFO_KERNEL_WHATSIN:" \
  8382. "LOADED" ":MENU_MODULE_SHOW_LOADED:" \
  8383. "REMOVE" ":MENU_MODULE_REMOVE:" \
  8384. "AVAILABLE" ":MENU_MODULE_SHOW_AVAILABLE:" \
  8385. "LOAD" ":MENU_MODULE_LOAD:" 2> $FILE_TMP_ANSWER || break
  8386.         item="`cat $FILE_TMP_ANSWER`"
  8387.         case $item in
  8388.         WHATSIN)
  8389.             Show_Kernel_Whatsin /boot/WHATSIN-`uname -r`-modular
  8390.             ;;
  8391.         LOADED)
  8392.             Menu_Module_Show_Loaded
  8393.             ;;
  8394.         REMOVE)
  8395.             Menu_Module_Remove
  8396.             ;;
  8397.         AVAILABLE)
  8398.             Menu_Module_Show_Available
  8399.             ;;
  8400.         LOAD)
  8401.             Menu_Module_Load
  8402.             ;;
  8403.         CREATE)
  8404.             Do_Create_New_Kernel
  8405.             ;;
  8406.         esac
  8407.     done
  8408.     return 0
  8409. }
  8410.  
  8411. List_MODULES_LOADED()
  8412. {
  8413.     lsmod | fgrep -v "#pages" 
  8414. }
  8415.  
  8416. Build_MODULES_LOADED()
  8417. {
  8418.     List_MODULES_LOADED | do_quote
  8419. }
  8420.  
  8421. List_MODULES_AVAILABLE()
  8422. {
  8423.     local module=
  8424.  
  8425.     for module in /floppy/lib/modules/`uname -r`/*/*.o ; do
  8426.         if [ -f $module ]; then
  8427.             echo "`basename $module .o`"
  8428.         fi
  8429.     done
  8430.     for module in /floppy/lib/modules/`uname -r`/*/*.o.gz ; do
  8431.         if [ -f $module ]; then
  8432.             echo "`basename $module .o.gz`"
  8433.         fi
  8434.     done
  8435.     for module in /lib/modules/`uname -r`/*/*.o ; do
  8436.         if [ -f $module ]; then
  8437.             echo "`basename $module .o`"
  8438.         fi
  8439.     done
  8440.     for module in /lib/modules/`uname -r`/*/*.o.gz ; do
  8441.         if [ -f $module ]; then
  8442.             echo "`basename $module .o.gz`"
  8443.         fi
  8444.     done
  8445. }
  8446.  
  8447. Build_MODULES_AVAILABLE()
  8448. {
  8449.     List_MODULES_AVAILABLE | do_quote
  8450. }
  8451.  
  8452. Menu_Module_Load()
  8453. {
  8454.     Choose --menutitle ":INFO_MODULES_LOADED_MENUTITLE:" --build Build_MODULES_AVAILABLE MODULE_LOAD || return 1
  8455.     if [ -z "$ANSWER" ]; then
  8456.         Error "no module specified"
  8457.         return 1
  8458.     fi
  8459.     Do_Load_Module "$ANSWER" || return 1
  8460.     return 0
  8461. }
  8462.  
  8463. Menu_Module_Remove()
  8464. {
  8465.     Choose --menutitle ":INFO_MODULES_LOADED_MENUTITLE:" --build Build_MODULES_LOADED MODULE_REMOVE || return 1
  8466.     if [ -z "$ANSWER" ]; then
  8467.         Error "no module specified"
  8468.         return 1
  8469.     fi
  8470.     rmmod $ANSWER || return 1
  8471.     return 0
  8472. }
  8473.  
  8474. Menu_Module_Show_Loaded()
  8475. {
  8476.     List_MODULES_LOADED > $FILE_TMP_MSG 2> $FILE_TMP_ERR
  8477.     if [ -s $FILE_TMP_ERR ]; then
  8478.         Error --file $FILE_TMP_ERR
  8479.         return 1
  8480.     fi
  8481.     if [ ! -s $FILE_TMP_MSG ]; then
  8482.         Msg ":INFO_NO_MODULES_LOADED:"
  8483.     else
  8484.         $CMD_BOX --help ":HELP_MODULES:" \
  8485. --title ":INFO_MODULES_LOADED_TITLE:" \
  8486. --menutitle ":INFO_MODULES_LOADED_MENUTITLE:" \
  8487. --text ":INFO_MODULES_LOADED_TEXT:" --browse $FILE_TMP_MSG
  8488.     fi
  8489. }
  8490.  
  8491. Menu_Module_Show_Available()
  8492. {
  8493.     List_MODULES_AVAILABLE > $FILE_TMP_MSG 2> $FILE_TMP_ERR
  8494.     if [ -s $FILE_TMP_ERR ]; then
  8495.         Error --file $FILE_TMP_ERR
  8496.         return 1
  8497.     fi
  8498.     if [ ! -s $FILE_TMP_MSG ]; then
  8499.         Msg ":INFO_NO_MODULES_AVAILABLE:"
  8500.     else
  8501.         $CMD_BOX --help ":HELP_MODULES:" \
  8502. --title ":INFO_MODULES_AVAILABLE_TITLE:" \
  8503. --text ":INFO_MODULES_AVAILABLE_TEXT:" --browse $FILE_TMP_MSG
  8504.     fi
  8505. }
  8506.  
  8507. Do_Load_Driver()
  8508. {
  8509.     local present=0
  8510.     local test_only=
  8511.     local silent_flag=
  8512.     local module_name=
  8513.     local module_type=
  8514.  
  8515.     if [ $# -gt 0 -a "$1" = '--test' ]; then
  8516.         test_only=true        
  8517.         shift 1
  8518.     fi
  8519.  
  8520.     if [ $# -ne 2 ]; then
  8521.         Panic ":ERR_WRONG_NUM_OF_ARGS: ($#)" || return 1
  8522.     fi
  8523.  
  8524.     case $1 in
  8525.     # filesystems
  8526.     filesystem)
  8527.         module_type=fs
  8528.         silent_flag='--silent'
  8529.         sysinfo --var --kernel 2>&1 >/dev/null | fgrep "INFO_FILESYSTEMS" > $FILE_TMP_MSG
  8530.         fgrep ":$2:" $FILE_TMP_MSG >/dev/null && return 0
  8531.         case $2 in
  8532.         nfs|hpfs|msdos|umsdos)
  8533.             module_name="$2"
  8534.             ;;
  8535.         iso9660)
  8536.             module_name="isofs"
  8537.             ;;
  8538.         esac
  8539.         ;;
  8540.     # CDROMs
  8541.     cdrom)
  8542.         module_type=misc
  8543.         sysinfo >/dev/null --var --cdrom 2> $FILE_TMP_MSG
  8544.         sed 's:/dev/sr:/dev/scd:' < $FILE_TMP_MSG |
  8545.             fgrep ":$2:" >/dev/null
  8546.         if [ $? -eq 0 ]; then
  8547.             return 0
  8548.         fi
  8549.         case $2 in
  8550.         /dev/arcd)
  8551.             module_name="arcd"
  8552.             ;;
  8553.         /dev/aztcd)
  8554.             module_name="aztcd"
  8555.             ;;
  8556.         /dev/bpcd)
  8557.             module_name="bpcd"
  8558.             ;;
  8559.         /dev/bpmcd)
  8560.             module_name="bpmcd"
  8561.             ;;
  8562.         /dev/cdu31a)
  8563.             module_name="cdu31a"
  8564.             ;;
  8565.         /dev/cdu535)
  8566.             module_name="sonycd535"
  8567.             ;;
  8568.         /dev/cm206cd)
  8569.             module_name="cm206"
  8570.             ;;
  8571.         /dev/dscd)
  8572.             module_name="dscd"
  8573.             ;;
  8574.         /dev/epcd)
  8575.             module_name="epcd"
  8576.             ;;
  8577.         /dev/gscd)
  8578.             module_name="gscd"
  8579.             ;;
  8580.         /dev/kicd)
  8581.             module_name="kicd"
  8582.             ;;
  8583.         /dev/oicd)
  8584.             module_name="oicd"
  8585.             ;;
  8586.         /dev/optcd)
  8587.             module_name="optcd"
  8588.             ;;
  8589.         /dev/mcd)
  8590.             module_name="mcd"
  8591.             ;;
  8592.         /dev/mcdx)
  8593.             module_name="mcdx"
  8594.             ;;
  8595.         /dev/pwcd)
  8596.             module_name="pwcd"
  8597.             ;;
  8598.         /dev/sbpcd)
  8599.             module_name="sbpcd"
  8600.             ;;
  8601.         /dev/sbpcd0)
  8602.             module_name="sbpcd"
  8603.             ;;
  8604.         /dev/sjcd)
  8605.             module_name="sjcd"
  8606.             ;;
  8607.         /dev/sonycd)
  8608.             module_name="cdu31a"
  8609.             ;;
  8610.         *)
  8611.             module_name=""
  8612.             ;;
  8613.         esac
  8614.         ;;
  8615.     ether)
  8616.         module_type=net
  8617.         silent_flag='--silent'
  8618.         sysinfo >/dev/null --var --ether 2> $FILE_TMP_MSG
  8619.         fgrep ":$2:" $FILE_TMP_MSG >/dev/null && return 0
  8620.         return 1
  8621.         ;;
  8622.     esac
  8623.     if [ -n "$test_only" ]; then
  8624.         return 1
  8625.     fi
  8626.  
  8627.     if [ -z "$module_name" ]; then
  8628.         if [ "$1" = "cdrom" ]; then
  8629.             echo "$2" | fgrep /dev/hd >/dev/null 2>&1
  8630.             if [ $? -eq 0 ]; then
  8631.                 # has to be an ATAPI CDROM...
  8632.                 return 0
  8633.             fi
  8634.         fi
  8635.         $CMD_BOX --msg "$2 ; :ERR_NO_DEVICE_AND_NO_MODULE:"
  8636.         return 1
  8637.     else
  8638.         Do_Load_Module $silent_flag $module_name $module_type
  8639.         retval=$?
  8640.         end_use /lib/modules/`uname -r`/$module_type/$module_name.o
  8641.     fi
  8642.     return $retval
  8643. }
  8644.  
  8645. Do_Load_Module()
  8646. {
  8647.   local silent_flag=
  8648.   local modpath=
  8649.   local subpath=
  8650.   local module=
  8651.   local modparam=
  8652.   local param=
  8653.  
  8654.   if [ $# -gt 0 -a "$1" = '--silent' ]; then
  8655.     silent_flag=true
  8656.     shift 1
  8657.   fi
  8658.   if [ $# -gt 1 -a "$1" = '--param' ]; then
  8659.     param="$2"
  8660.     shift 2
  8661.   fi
  8662.  
  8663.   if [ $# -lt 1 ]; then Panic ":ERR_INVALID_PARAMS:" ; fi
  8664.  
  8665.   # check whether it's already loaded
  8666.   lsmod | sed -n "/^$1/p" > $FILE_TMP_ANSWER
  8667.   if [ -s $FILE_TMP_ANSWER ]; then
  8668.     Debug "Module $1 seems to be loaded..."
  8669.     return 0
  8670.   else
  8671.     Debug "Module $1 is not loaded..."
  8672.   fi
  8673.  
  8674.   if [ -n "$param" ]; then
  8675.     modparam="$param"
  8676.   else
  8677.     # initialize with boot params
  8678.     if [ -s $FILE_BOOT_PARAMS ]; then
  8679.       Debug "Search for boot param <$1> in <$FILE_BOOT_PARAMS>..."
  8680.       sed -n "/^$1=/p" $FILE_BOOT_PARAMS > $FILE_TMP_ANSWER
  8681.       modparam="`cat $FILE_TMP_ANSWER`"
  8682.       Debug "found boot param <$modparam>"
  8683.     fi
  8684.   fi
  8685.  
  8686.   # check whether it's available 
  8687.   modpath=/lib/modules/`uname -r`
  8688.   for subpath in $2 block cdrom fs ipv4 misc net pcmcia scsi ; do
  8689.     module="$modpath/$subpath/$1.o"
  8690.     if [ -s $module ]; then
  8691.       break
  8692.     elif [ -s ${module}.gz ]; then
  8693.       gzip -df ${module}.gz && break
  8694.     elif [ -s /source${module} ]; then
  8695.       ln -sf /source${module} $module && break
  8696.     elif [ -s /floppy${module}.gz ]; then
  8697.       gzip -dc /floppy${module}.gz > $module && break
  8698.     fi
  8699.     module=
  8700.   done 
  8701.  
  8702.   if [ -z "$module" ]; then
  8703.     $CMD_BOX --msg "module $1.o ; :ERR_MODULE_NOT_AVAILABLE:"
  8704.     return 1
  8705.   fi 
  8706.  
  8707.   while [ 1 ]; do
  8708.     # dirty hack to adjust symbol names used for modules
  8709.     echo $modparam | sed '{
  8710.     s/^cm206=/cm206_base=/
  8711.     s/^gscd=/gscd_port=/
  8712.     s/^sonycd535=/sony535_cd_base_io=/
  8713.     }' > $FILE_TMP_ANSWER
  8714.     modparam="`cat $FILE_TMP_ANSWER`"
  8715.     if [ -z "$silent_flag" ]; then
  8716.       Info "module $1.o ; :INFO_MODULE_LOADING:"
  8717.     fi
  8718.     insmod $module $modparam >$FILE_TMP_ERR 2>&1 && break
  8719.     $CMD_BOX --msg "module $1.o ; :ERR_MODULE_LOADING_FAILED:"
  8720.     rmmod $1 >/dev/null 2>&1
  8721.     Ask_String BOOT_PARAM $modparam || return 1
  8722.     modparam="$ANSWER"
  8723.     if [ -z "$modparam" ]; then return 1 ; fi
  8724.   done
  8725.   echo "$1" >> /tmp/modules
  8726.   mkdir -p /etc/modules/options
  8727.   if [ -n "$modparam" ]; then
  8728.     echo "$modparam" > /etc/modules/options/$1
  8729.   else
  8730.     rm -f /etc/modules/options/$1
  8731.   fi
  8732.   return 0
  8733. }
  8734.  
  8735. Do_Unload_Module()
  8736. {
  8737.   local f_name=Do_Unload_Module
  8738.   local f_args=1 # (modulename) ->
  8739.  
  8740.   Check_Args $f_name $f_args $# "$@" || return 255
  8741.   Debug "unloading module $1 ..."
  8742.   Info "module $1.o ; :INFO_MODULE_UNLOADING:"
  8743.   rmmod $1 && return 0
  8744.   return 1
  8745. }
  8746.  
  8747. # libLSTnet - network handling library shared between several scripts
  8748. #
  8749. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  8750. #
  8751.  
  8752. Do_Ifcfg()
  8753. {
  8754.     local interface="$1"
  8755.     local action="$2"
  8756.  
  8757.     Debug "Do_Ifcfg called with <$1> <$2>"
  8758.     case $interface in
  8759.     lo)
  8760.         Do_Ifcfg_lo $action
  8761.         ;;
  8762.     eth0)
  8763.         Do_Ifcfg_eth 0 $action
  8764.         ;;
  8765.     eth1)
  8766.         Do_Ifcfg_eth 1 $action
  8767.         ;;
  8768.     tr0)
  8769.         Do_Ifcfg_tr 0 $action
  8770.         ;;
  8771.     plip0)
  8772.         Do_Ifcfg_plip 0 $action
  8773.         ;;
  8774.     plip1)
  8775.         Do_Ifcfg_plip 1 $action
  8776.         ;;
  8777.     plip2)
  8778.         Do_Ifcfg_plip 2 $action
  8779.         ;;
  8780.     default)
  8781.         Do_Ifcfg_default $action
  8782.         ;;
  8783.     esac
  8784. }
  8785.  
  8786. Do_Ifcfg_default()
  8787. {
  8788.     local router="`Get_Val CONF_ROUTER1_IP`"
  8789.  
  8790.     # route del default
  8791.     if [ "$1" = "up" ]; then
  8792.         if [ -n "$router" ]; then
  8793.             Debug "route add default gw $router"
  8794.             route add default gw $router
  8795.         fi
  8796.     fi
  8797. }
  8798.  
  8799. Do_Ifcfg_plip()
  8800. {
  8801.     local num="$1"
  8802.     local plipx="plip${num}"
  8803.     local ip="`Get_Val CONF_${plipx}_IP`"
  8804.     local remote_ip="`Get_Val CONF_${plipx}_REMOTE_IP`"
  8805.  
  8806.     Debug "Debug: Do_Ifcfg_plip $1 $2"
  8807.     Debug "Debug: net = <$net>"
  8808.     # ifconfig $plipx down
  8809.     # route del -net $net
  8810.     if [ "$2" = "up" ]; then
  8811.         Debug "bringing up interface"
  8812.         Debug "ifconfig $plipx $ip pointopoint $remote_ip"
  8813.         ifconfig $plipx $ip pointopoint $remote_ip
  8814.         Debug "route add -host $remote_ip gw $ip"
  8815.         route add -host $remote_ip gw $ip
  8816.     fi
  8817. }
  8818.  
  8819. Do_Ifcfg_tr()
  8820. {
  8821.     local num="$1"
  8822.     local trx="tr${num}"
  8823.     local ip="`Get_Val CONF_${trx}_IP`"
  8824.     local net="`Get_Val CONF_${trx}_NET`"
  8825.     local mask="`Get_Val CONF_${trx}_MASK`"
  8826.     local bcast="`Get_Val CONF_${trx}_BCAST`"
  8827.  
  8828.     Debug "Debug: Do_Ifcfg_tr $1 $2"
  8829.     Debug "Debug: net = <$net>"
  8830.     # ifconfig $trx down
  8831.     # route del -net $net
  8832.     if [ "$2" = "up" ]; then
  8833.         Debug "bringing up interface $trx"
  8834.         Debug "ifconfig $trx $ip netmask $mask broadcast $bcast"
  8835.         ifconfig $trx $ip netmask $mask broadcast $bcast
  8836.         Debug "route add -net $net"
  8837.         route add -net $net
  8838.     fi
  8839. }
  8840.  
  8841. Do_Ifcfg_eth()
  8842. {
  8843.     local num="$1"
  8844.     local ethx="eth${num}"
  8845.     local ip="`Get_Val CONF_${ethx}_IP`"
  8846.     local net="`Get_Val CONF_${ethx}_NET`"
  8847.     local mask="`Get_Val CONF_${ethx}_MASK`"
  8848.     local bcast="`Get_Val CONF_${ethx}_BCAST`"
  8849.  
  8850.     Debug "Debug: Do_Ifcfg_eth $1 $2"
  8851.     Debug "Debug: net = <$net>"
  8852.     # ifconfig $ethx down
  8853.     # route del -net $net
  8854.     if [ "$2" = "up" ]; then
  8855.         Debug "bringing up interface $ethx"
  8856.         Debug "ifconfig $ethx $ip netmask $mask broadcast $bcast"
  8857.         ifconfig $ethx $ip netmask $mask broadcast $bcast
  8858.         Debug "route add -net $net"
  8859.         route add -net $net
  8860.     fi
  8861. }
  8862.  
  8863. Do_Ifcfg_lo()
  8864. {
  8865.     # ifconfig lo down
  8866.     # route del -net 127.0.0.0
  8867.     if [ "$1" = "up" ]; then
  8868.         Debug "ifconfig lo 127.0.0.1"
  8869.         ifconfig lo 127.0.0.1
  8870.         Debug "route add -net 127.0.0.0"
  8871.         route add -net 127.0.0.0
  8872.     fi
  8873. }
  8874.  
  8875. Menu_Config_Nethost()
  8876. {
  8877.     Menu_Config_FQ_Name || return 1
  8878.     Do_Ifcfg lo up
  8879.     Menu_Config_Netdev || return 1
  8880.     Get_netprobe_Info
  8881.     Menu_Config_Router $1
  8882.     Do_Ifcfg default up
  8883. }
  8884.  
  8885. # Ask_HOSTNAME ( {FQ,ETHER,ROUTER,NFS_SERVER,DNS_SERVER,MAIL_SERVER}, [default] )
  8886. #
  8887. Ask_HOSTNAME()
  8888. {
  8889.   while [ 1 ]; do
  8890.     # Ask_String --prehelp ":HELP_HOSTNAME:" $1_NAME $2 || return 1
  8891.     Ask_String $1_NAME $2 || return 1
  8892.     # Fixme Check_Hostname_Valid "$ANSWER" && return 0
  8893.     return 0
  8894.   done
  8895. }
  8896.  
  8897. # Ask_IP ( [--none] [--pretext PRETEXT ] [--help HELPTEXT] [--num NO] VARNAME [default] )
  8898. #
  8899. Ask_IP()
  8900. {
  8901.   local num=
  8902.   local help=":HELP_IP:"
  8903.   local pretext=""
  8904.   local var=
  8905.   local defval=
  8906.   local none_flag=
  8907.   local ipaddr=
  8908.  
  8909.   if [ $# -gt 0 -a "$1" = '--none' ]; then
  8910.     none_flag=true
  8911.     shift 1
  8912.   fi
  8913.   if [ $# -gt 1 -a "$1" = "--pretext" ]; then
  8914.     pretext="$2"
  8915.     shift 2
  8916.   fi
  8917.   if [ $# -gt 1 -a "$1" = "--help" ]; then
  8918.     help="$2"
  8919.     shift 2
  8920.   fi
  8921.   if [ $# -gt 1 -a "$1" = "--num" ]; then
  8922.     num="$2"
  8923.     shift 2
  8924.   fi
  8925.   if [ $# -gt 0 ]; then
  8926.     if [ $# -gt 1 ]; then
  8927.       defval="$2"
  8928.     fi
  8929.     if [ -z "$defval" ]; then
  8930.       defval="`Get_Val CONF_$1${num}_IP`"
  8931.     fi
  8932.     var="$1_IP"
  8933.   fi
  8934.   if [ -z "$var" ]; then
  8935.     var="IP"
  8936.   fi
  8937.  
  8938.   while [ 1 ]; do
  8939.     Ask_String --pretext "$pretext" --help "$help" $var $defval || return 1
  8940.     if [ -z "$ANSWER" ]; then
  8941.       if [ -n "$none_flag" ]; then return 0 ; fi
  8942.     fi
  8943.     Check_IP_Addr_Valid "$ANSWER" || continue
  8944.     echo "new ANSWER = $ANSWER" >> /dev/tty4
  8945.     return 0
  8946.   done
  8947. }
  8948.  
  8949. Check_Host_Known()
  8950. {
  8951.   local f_name=Check_Host_Known
  8952.   local f_args=1 # (hostname) -> "$FILE_ETC_HOSTS entry"
  8953.  
  8954.   Check_Args $f_name $f_args $# "$@" || return 255
  8955.   sed -n "/ $1/p" $FILE_ETC_HOSTS
  8956. }
  8957.  
  8958. Check_IP_Addr_Known()
  8959. {
  8960.   local f_name=Check_IP_Addr_Known
  8961.   local f_args=1 # (ipaddr) -> "$FILE_ETC_HOSTS entry"
  8962.  
  8963.   Check_Args $f_name $f_args $# "$@" || return 255
  8964.   sed -n "/^$1 /p" $FILE_ETC_HOSTS
  8965. }
  8966.  
  8967. # Verify IP address and set ANSWER to an octal clean value and
  8968. # set ANSWER2 to the corresponding netmask
  8969. #
  8970. Check_IP_Addr_Valid()
  8971. {
  8972.     local f_name=Check_IP_Addr_Valid
  8973.     local f_args=1 # (ipaddr) -> ANSWER2
  8974.     local field=
  8975.     local field1=
  8976.     local field2=
  8977.     local field3=
  8978.     local field4=
  8979.     local good=
  8980.     local octfree=
  8981.     export ANSWER2=
  8982.  
  8983.     Check_Args $f_name $f_args $# "$@" || return 255
  8984.     # Test for invalid chars
  8985.     if [ -n "`Check_Chars_Valid "$1" "0123456789\."`" ]; then
  8986.         Error ":ERR_INVALID_IP_ADDR:"
  8987.         return 1
  8988.     fi
  8989.  
  8990.     # Test for 3 dots
  8991.     if [ "`echo $1 | sed 's/[^\.]//g'`" != '...' ]; then
  8992.         Error ":ERR_INVALID_IP_ADDR:"
  8993.         return 1
  8994.     fi
  8995.  
  8996.     IFS='.' read field1 field2 field3 field4 << EOF
  8997. $1
  8998. EOF
  8999.     for field in $field1 $field2 $field3 $field4 ; do
  9000.         if [ $field -gt 255 -o 0 -gt $field ]; then
  9001.             Error ":ERR_INVALID_IP_ADDR:"
  9002.             return 1
  9003.         fi
  9004.         # make sure IP address is octal clean to make do_netcalc happy
  9005.         good="$field"
  9006.         if [ $field -gt 0 ]; then
  9007.             # cut off heading zeros
  9008.             good="`echo $field | sed 's/^[0]*//'`"
  9009.         fi
  9010.         if [ -z "$octfree" ]; then
  9011.             octfree="${good}"
  9012.         else
  9013.             octfree="${octfree}.${good}"
  9014.         fi
  9015.     done
  9016.     # overwrite ANSWER (global) with octal free value
  9017.     echo "old ANSWER = $ANSWER" >> /dev/tty4
  9018.     echo "octfree = $octfree" >> /dev/tty4
  9019.     ANSWER="$octfree"
  9020.     ANSWER2="`do_netcalc -m $ANSWER`"
  9021.     return 0
  9022. }
  9023.  
  9024. # Verify netmask for an IP addr and set ANSWER2 to corresponding broadcast
  9025. # and ANSWER3 to corresponding net
  9026. #
  9027. Check_Netmask_Valid()
  9028. {
  9029.     local f_name=Check_IP_Addr_Valid
  9030.     local f_args=2 # (netmask, ipaddr) -> ANSWER2, ANSWER3
  9031.     local i
  9032.     local field
  9033.     export ANSWER2
  9034.     export ANSWER3
  9035.  
  9036.     Check_Args $f_name $f_args $# "$@" || return 255
  9037.     Check_IP_Addr_Valid $2 || return 1 
  9038.  
  9039.     ANSWER2=
  9040.     ANSWER3=
  9041.  
  9042.     # Test for invalid chars
  9043.     if [ -n "`Check_Chars_Valid "$1" "0123456789\."`" ]; then
  9044.         Error ":ERR_INVALID_NETMASK:"
  9045.         return 1
  9046.     fi
  9047.  
  9048.     # Test for 3 dots
  9049.     if [ "`echo $1 | sed 's/[^\.]//g'`" != '...' ]; then
  9050.         Error ":ERR_INVALID_NETMASK:"
  9051.         return 1
  9052.     fi
  9053.  
  9054.     for i in 1 2 3 4 ; do
  9055.         field="`echo $1 | cut -d. -f $i`"
  9056.         if [ $field -gt 255 -o 0 -gt $field ]; then
  9057.             Error ":ERR_INVALID_NETMASK:"
  9058.             return 1
  9059.         fi
  9060.     done
  9061.     ANSWER="$1"
  9062.     ANSWER2="`do_netcalc -b $2 $1`"
  9063.     ANSWER3="`do_netcalc -n $2 $1`"
  9064.     return 0
  9065. }
  9066.  
  9067. Get_Net_Info()
  9068. {
  9069.     # net info
  9070.     # FIXME: hardcoded strings
  9071.     echo
  9072.     echo -n "Hostname        : "
  9073.     hostname
  9074.     echo
  9075.     echo -n "NIS domain      : "
  9076.     domainname
  9077.     echo
  9078.     echo "Network interfaces :"
  9079.     cat /proc/net/dev
  9080.     echo
  9081.     echo "Active interfaces  :"
  9082.     ifconfig -a
  9083.     echo
  9084.     echo "Routing table      :"
  9085.     route -n
  9086.     if [ -f /usr/sbin/netstat ]; then
  9087.         echo
  9088.         echo "Network statistics :"
  9089.         netstat -i
  9090.     fi
  9091.     if [ -f /usr/sbin/rpcinfo ]; then
  9092.         echo
  9093.         echo "RPC informations   :"
  9094.         rpcinfo -p
  9095.     fi
  9096.     if [ -f /usr/sbin/showmount ]; then
  9097.         echo
  9098.         echo "Exported filesystems :"
  9099.         showmount -e
  9100.     fi
  9101. }
  9102.  
  9103. Menu_Analyse_Net()
  9104. {
  9105.     Show_Net_Info
  9106. }
  9107.  
  9108. Do_Setup_Mail()
  9109. {
  9110.     local fqhn=
  9111.     local shortname=
  9112.     local domainname=
  9113.  
  9114.     fqhn="`Get_Val CONF_FQ_HOSTNAME $CONF_FQ_HOSTNAME`"
  9115.     shortname="`echo $CONF_FQ_HOSTNAME | cut -d'.' -f 1`"
  9116.     domainname="`echo $CONF_FQ_HOSTNAME | cut -d'.' -f 2-`"
  9117.  
  9118.     #
  9119.     # smail konfigurieren
  9120.     #
  9121.     if [ -f $FILE_SMAIL_CONFIG.sample ]; then
  9122.         sed "{
  9123.                 s/HOSTNAME/$shortname/g
  9124.                 s/DOMAINNAME/$domainname/g
  9125.                 }" $FILE_SMAIL_CONFIG.sample > $FILE_SMAIL_CONFIG
  9126.         chmod 644 $FILE_SMAIL_CONFIG
  9127.         if [ -f /usr/lib/smail/tools.linux/mkconfig ]; then
  9128.             # Msg ":INFO_PLEASE_CONFIGURE_SMAIL:"
  9129.             ( cd /usr/lib/smail ; tools.linux/mkconfig )
  9130.         fi
  9131.     fi
  9132.  
  9133.     #
  9134.     # elm konfigurieren
  9135.     #
  9136.     if [ -f $FILE_ELM_RC.sample ]; then
  9137.         sed "{
  9138.                 s/DOMAINNAME/$domainname/g
  9139.                 s/HOSTNAME/$shortname/g
  9140.                 }" $FILE_ELM_RC.sample > $FILE_ELM_RC
  9141.         chmod 644 $FILE_ELM_RC
  9142.     fi
  9143. }
  9144.  
  9145. Do_Setup_FQ_Name()
  9146. {
  9147.   local fqhn=
  9148.   local shortname=
  9149.   local domainname=
  9150.  
  9151.   fqhn="`Get_Val CONF_FQ_HOSTNAME`"
  9152.   shortname="`echo $fqhn | cut -d'.' -f 1`"
  9153.   domainname="`echo $fqhn | cut -d'.' -f 2-`"
  9154.   if [ -n "$shortname" ]; then
  9155.     hostname $shortname
  9156.     Do_Store CONF_NODENAME "$shortname"
  9157.     Do_Store CONF_DNS_DOMAIN "$domainname"
  9158.     Do_Store CONF_DNS_SEARCH "$domainname"
  9159.     mkdir -p $DIR_TARGET/etc/sysconfig
  9160.     touch $DIR_TARGET/etc/sysconfig/network
  9161.     set_val -f $DIR_TARGET/etc/sysconfig/network HOSTNAME $fqhn
  9162.   fi
  9163.   Set_etc_HOSTNAME
  9164.   Do_Setup_DNS
  9165. }
  9166.  
  9167. Menu_Config_FQ_Name()
  9168. {
  9169.   local fqhn=
  9170.   local shortname=
  9171.   local domainname=
  9172.   local eth0name=
  9173.  
  9174.   fqhn="`Get_Val CONF_FQ_HOSTNAME`"
  9175.   Ask_HOSTNAME FQ $fqhn || return 1
  9176.   if [ -z "$ANSWER" ]; then return 1 ; fi
  9177.   fqhn="$ANSWER"
  9178.   Do_Store CONF_FQ_HOSTNAME "$fqhn"
  9179.   Do_Setup_FQ_Name
  9180.   eth0name="`Get_Val CONF_eth0_NAME`"
  9181.   if [ -n "$eth0name" ]; then
  9182.       Do_Store CONF_eth0_NAME "$fqhn"
  9183.   fi
  9184.   Do_Setup_Hosts
  9185.   return 0
  9186. }
  9187.  
  9188. Menu_Config_Net_Connect()
  9189. {
  9190.   local item
  9191.  
  9192.   # "Menu_Config_UUCP" ":MENU_CONFIG_UUCP:"
  9193.   while [ 1 ]; do
  9194.     if [ -z "$item" ]; then item="Menu_Config_Ether" ; fi
  9195.     $CMD_BOX --help ":MENU_CONFIG_NET_CONNECT_HELP:" \
  9196. --default "$item" \
  9197. --title ":MENU_CONFIG_NET_CONNECT_TITLE:" \
  9198. --menu ":MENU_CONFIG_NET_CONNECT_TEXT:" \
  9199. "Menu_Config_Ether" ":MENU_CONFIG_ETHER:" \
  9200. "Menu_Config_Router" ":MENU_CONFIG_ROUTER:" 2> $FILE_TMP_ANSWER || break
  9201.     COMMAND="`cat $FILE_TMP_ANSWER`"
  9202.     if [ -n "$COMMAND" ]; then
  9203.       $COMMAND
  9204.     fi
  9205.   done
  9206. }
  9207.  
  9208. Do_Setup_DNS()
  9209. {
  9210.     local fqhn="`Get_Val CONF_FQ_HOSTNAME`"
  9211.     local domainname="`echo $fqhn | cut -d'.' -f 2-`"
  9212.     local domain="`Get_Val CONF_DNS_DOMAIN`"
  9213.     local search="`Get_Val CONF_DNS_SEARCH`"
  9214.     local server1="`Get_Val CONF_DNS_SERVER1_IP`"
  9215.     local server2="`Get_Val CONF_DNS_SERVER2_IP`"
  9216.     local server3="`Get_Val CONF_DNS_SERVER3_IP`"
  9217.  
  9218.     local DomainLine=
  9219.     local SearchLine=
  9220.     local Server1Line=
  9221.     local Server2Line=
  9222.     local Server3Line=
  9223.  
  9224.     if [ -n "$domain" ]; then
  9225.         DomainLine="domain $domain"
  9226.     else
  9227.         if [ -n "$domainname" ]; then
  9228.             domain="$domainname"
  9229.             Do_Store CONF_DNS_DOMAIN "$domain"
  9230.             DomainLine="domain $domain"
  9231.         fi
  9232.     fi
  9233.     if [ -n "$search" ]; then
  9234.         SearchLine="search $search"
  9235.     else
  9236.         if [ -n "$domain" ]; then
  9237.             search="$domain"
  9238.             Do_Store CONF_DNS_SEARCH "$search"
  9239.             SearchLine="search $search"
  9240.         fi
  9241.     fi
  9242.     if [ -n "$server1" ]; then
  9243.         Server1Line="nameserver $server1"
  9244.     fi
  9245.     if [ -n "$server2" ]; then
  9246.         Server2Line="nameserver $server2"
  9247.     fi
  9248.     if [ -n "$server3" ]; then
  9249.         Server3Line="nameserver $server3"
  9250.     fi
  9251.  
  9252.     # we don't prefix it with $DIR_TARGET as we copy it later
  9253.  
  9254.     cat << EOF > $FILE_ETC_RESOLV_CONF
  9255. # $FILE_ETC_RESOLV_CONF - DNS setup file
  9256. #
  9257. # possible entries are:
  9258. #
  9259. #    domain <domain>            Local domain name. If not present, the
  9260. #                    gethostbyname syscall is used to
  9261. #                    determine the local domain name.
  9262. #
  9263. #    search <list_of_domains>    Search list for hostname lookup.
  9264. #                    The search list is normally determined
  9265. #                    from the local domain name but it
  9266. #                    can be set to a list of domains.
  9267. #
  9268. #    nameserver <ip_addr>        Define which server to contact
  9269. #                                       for DNS lookups. If there are
  9270. #                    multiple nameserver lines (Max=3),
  9271. #                    they are queried in the listed order.
  9272. #
  9273. # !!! Automatically generated by LISA from /etc/system.cnf. Do not edit !!!
  9274. #
  9275. $DomainLine
  9276. $SearchLine
  9277. $Server1Line
  9278. $Server2Line
  9279. $Server3Line
  9280. EOF
  9281.     chmod 644 $FILE_ETC_RESOLV_CONF
  9282. }
  9283.  
  9284. Menu_Config_DNS()
  9285. {
  9286.     local server1="`Get_Val CONF_DNS_SERVER1_IP`"
  9287.     local server2="`Get_Val CONF_DNS_SERVER2_IP`"
  9288.     local server3="`Get_Val CONF_DNS_SERVER3_IP`"
  9289.     local dnssetup=NONE
  9290.  
  9291.     local num
  9292.     local retry
  9293.     local none_flag
  9294.  
  9295.     while [ 1 ]; do
  9296.         retry=
  9297.         none_flag=
  9298.         Ask_Bool DNS_SERVER || return 1
  9299.         if [ "$ANSWER" = "0" ]; then
  9300.             dnssetup=CLIENT
  9301.         else
  9302.             dnssetup=SERVER
  9303.         fi
  9304.  
  9305.         case $dnssetup in
  9306.         SERVER)
  9307.             # Ask_Bool DNS_SERVER_LOCAL n || return 1
  9308.             ANSWER=1
  9309.             case $ANSWER in
  9310.             0)
  9311.                 # setup localhost as nameserver
  9312.                 server1="127.0.0.1"
  9313.                 server2=
  9314.                 server3=
  9315.                 Err_Not_Implemented
  9316.                 ;;
  9317.             1)
  9318.                 # then we just use $FILE_ETC_HOSTS
  9319.                 server1=
  9320.                 server2=
  9321.                 server3=
  9322.                 ;;
  9323.             esac
  9324.             ;;
  9325.         CLIENT)
  9326.             # We are a DNS client. Ask for IP addr of DNS servers.
  9327.             for num in 1 2 3 ; do
  9328.                 if [ $num -gt 1 ]; then none_flag='--none' ; fi
  9329.                 none_flag='--none'
  9330.                 Ask_IP $none_flag --pretext "DNS server $num ; " --help ":HELP_IP:" --num $num DNS_SERVER
  9331.                 if [ $? -ne 0 ]; then retry=true ; break ; fi
  9332.                 if [ -z "$ANSWER" ]; then break ; fi
  9333.                 eval "`echo \"server$num=$ANSWER\"`"
  9334.             done
  9335.             ;;
  9336.         esac
  9337.         if [ -n "$retry" ]; then continue ; fi
  9338.         break
  9339.     done
  9340.     Do_Store CONF_DNS_SERVER1_IP "$server1"
  9341.     Do_Store CONF_DNS_SERVER2_IP "$server2"
  9342.     Do_Store CONF_DNS_SERVER3_IP "$server3"
  9343.     Do_Setup_DNS
  9344. }
  9345.  
  9346. Menu_Config_Netdev()
  9347. {
  9348.     export ANSWER=
  9349.     local supported_netdevs="eth0 eth1 tr0 plip0 plip1 plip2"
  9350.     local dev=
  9351.     local ip=
  9352.     local remote_ip=
  9353.     local mask=
  9354.     local bcast=
  9355.     local net=
  9356.     local name=
  9357.     local trydev=
  9358.  
  9359.     # FIXME: supports all network devices, not only a limited list
  9360.     for trydev in $supported_netdevs ; do
  9361.         if [ -n "`fgrep $trydev /proc/net/dev`" ]; then
  9362.             dev="$trydev"
  9363.             break
  9364.         fi
  9365.     done
  9366.  
  9367.     # FIXME: A list of available devices should be created dynamically
  9368.     Ask_String ETHER_DEV $dev || return 1
  9369.     dev="$ANSWER"
  9370.     if [ -z "`fgrep $dev /proc/net/dev`" ]; then
  9371.         Error "$dev ; :ERR_NO_DEVICE_AND_NO_MODULE:"
  9372.         # FIXME: this should fall back to module loading...
  9373.         return 1
  9374.     fi
  9375.  
  9376.     case $dev in
  9377.     lo|eth0|eth1|plip0|plip1|plip2|tr0)
  9378.         ;;
  9379.     *)
  9380.         Err_Not_Implemented
  9381.         return 1
  9382.         ;;
  9383.     esac
  9384.  
  9385.     while [ 1 ]; do
  9386.         # interface device
  9387.         Do_Store CONF_${dev}_DEV "$dev"
  9388.  
  9389.         # interface ip
  9390.         ip="`Get_Val CONF_${dev}_IP`"
  9391.         if [ -z "$ip" ]; then
  9392.             ip=192.168.0.1
  9393.         fi
  9394.         Ask_IP ETHER $ip || continue
  9395.         ip="$ANSWER"
  9396.         Do_Store CONF_${dev}_IP "$ip"
  9397.  
  9398.         if [ "$dev" = "plip0" -o "$dev" = "plip1" ]; then
  9399.             # remote (pointopoint) ip
  9400.             remote_ip="`Get_Val CONF_${dev}_REMOTE_IP`"
  9401.             if [ -z "$remote_ip" ]; then
  9402.                 remote_ip=192.168.0.2
  9403.             fi
  9404.             Ask_IP ETHER_REMOTE $remote_ip || continue
  9405.             remote_ip="$ANSWER"
  9406.             Do_Store CONF_${dev}_REMOTE_IP "$remote_ip"
  9407.         else
  9408.             # interface netmask, broadcast and netroute
  9409.             if [ -z "$ANSWER2" ]; then
  9410.                 ANSWER2="255.255.255.0"
  9411.             fi
  9412.  
  9413.             mask="`Get_Val CONF_${dev}_MASK`"
  9414.             if [ -z "$mask" ]; then
  9415.                 mask="$ANSWER2"
  9416.             fi
  9417.             Ask_String NETMASK $mask || continue
  9418.             mask="$ANSWER"
  9419.             Check_Netmask_Valid "$mask" $ip || continue
  9420.             bcast="$ANSWER2"
  9421.             net="$ANSWER3"
  9422.  
  9423.             Ask_String BROADCAST $bcast || continue
  9424.             bcast="$ANSWER"
  9425.  
  9426.             Do_Store CONF_${dev}_MASK "$mask"
  9427.             Do_Store CONF_${dev}_BCAST "$bcast"
  9428.             Do_Store CONF_${dev}_NET "$net"
  9429.         fi
  9430.         break
  9431.     done
  9432.  
  9433.     # assumption: interface name = hostname
  9434.     name="`Get_Val CONF_FQ_HOSTNAME`"
  9435.     Do_Store CONF_${dev}_NAME "$name"
  9436.     Do_Setup_Hosts
  9437.     Set_network
  9438.     Do_Ifcfg $dev up > $FILE_TMP_ERR 2>&1
  9439.     Do_Store CONF_${dev}_STAT up
  9440.     Set_ifcfg ${dev}
  9441.     ANSWER="${dev}"
  9442.     return 0
  9443. }
  9444.  
  9445. Menu_Config_Ether()
  9446. {
  9447.     export ANSWER=
  9448.     local first_install=
  9449.     local shortname=
  9450.     local fqhn=
  9451.     local dev=eth0
  9452.     local ip=
  9453.     local pointopoint=
  9454.     local mask=
  9455.     local bcast=
  9456.     local net=
  9457.     local name=
  9458.  
  9459.     if [ $# -gt 0 -a "$1" = "first" ]; then
  9460.         first_install=true
  9461.         shift 1
  9462.     fi
  9463.  
  9464.     if [ $# -gt 0 -a "$1" = "eth1" ]; then
  9465.         dev=eth1
  9466.         shift 1
  9467.     fi
  9468.  
  9469.     while [ 1 ]; do
  9470.         if [ -n "$first_install" ]; then
  9471.             Do_Store CONF_${dev}_STAT up
  9472.         else
  9473.             Ask_Bool ETHER || return 1
  9474.             case $ANSWER in 
  9475.             0)
  9476.                 Do_Store CONF_${dev}_STAT up
  9477.                 prep_use NETCONF
  9478.                 ;;
  9479.             1)
  9480.                 Do_Store CONF_${dev}_STAT down
  9481.                 return 0
  9482.                 ;;
  9483.             esac
  9484.         fi
  9485.  
  9486.         # interface device
  9487.         Debug "Calling Get_Val"
  9488.         dev="`Get_Val CONF_${dev}_DEV`"
  9489.         if [ -z "$dev" ]; then
  9490.             dev="eth0"
  9491.         fi
  9492.         Ask_String ETHER_DEV $dev || return 1
  9493.         dev="$ANSWER"
  9494.         if [ -z "`fgrep $dev /proc/net/dev`" ]; then
  9495.             Error "$dev ; :ERR_NO_DEVICE_AND_NO_MODULE:"
  9496.             # FIXME: this should fall back to module loading...
  9497.             return 1
  9498.         fi
  9499.         Do_Store CONF_${dev}_DEV "$dev"
  9500.  
  9501.         # interface ip
  9502.         ip="`Get_Val CONF_${dev}_IP`"
  9503.         Ask_IP ETHER $ip || continue
  9504.         ip="$ANSWER"
  9505.         Do_Store CONF_${dev}_IP "$ip"
  9506.  
  9507.         # interface netmask, broadcast and netroute
  9508.         if [ -z "$ANSWER2" ]; then
  9509.             ANSWER2="255.255.255.0"
  9510.         fi
  9511.  
  9512.         mask="`Get_Val CONF_${dev}_MASK`"
  9513.         if [ -z "$mask" ]; then
  9514.             mask="$ANSWER2"
  9515.         fi
  9516.         Ask_String NETMASK $mask || continue
  9517.         Check_Netmask_Valid "$ANSWER" $ip || continue
  9518.         mask="$ANSWER"
  9519.         bcast="$ANSWER2"
  9520.         net="$ANSWER3"
  9521.  
  9522.         Ask_String BROADCAST $bcast || continue
  9523.         bcast="$ANSWER"
  9524.  
  9525.         Do_Store CONF_${dev}_MASK "$mask"
  9526.         Do_Store CONF_${dev}_BCAST "$bcast"
  9527.         Do_Store CONF_${dev}_NET "$net"
  9528.         break
  9529.     done
  9530.  
  9531.     # assumption: interface name = hostname
  9532.     fqhn="`Get_Val CONF_FQ_HOSTNAME`"
  9533.     name="$fqhn"
  9534.     Do_Store CONF_${dev}_NAME "$name"
  9535.     Do_Setup_Hosts
  9536.     Set_network
  9537.     Do_Ifcfg $dev up > $FILE_TMP_ERR 2>&1
  9538.     Set_ifcfg ${dev}
  9539.     return 0
  9540. }
  9541.  
  9542. Do_Setup_Hosts()
  9543. {
  9544.     local fqhn="`Get_Val CONF_FQ_HOSTNAME`"
  9545.     local nodename="`echo $fqhn | cut -d'.' -f 1`"
  9546.     local eth0name="`Get_Val CONF_eth0_NAME`"
  9547.     local eth1name="`Get_Val CONF_eth1_NAME`"
  9548.     local tr0name="`Get_Val CONF_tr0_NAME`"
  9549.  
  9550.     local LocalhostLine=
  9551.     local eth0Line=
  9552.     local eth1Line=
  9553.     local tr0Line=
  9554.     local shortname=
  9555.  
  9556.     if [ -n "$eth0name" ]; then
  9557.         shortname="`echo $eth0name | cut -d'.' -f 1`"
  9558.         eth0Line="`Get_Val CONF_eth0_IP` $eth0name $shortname"
  9559.     fi
  9560.     if [ -n "$eth1name" ]; then
  9561.         shortname="`echo $eth1name | cut -d'.' -f 1`"
  9562.         eth1Line="`Get_Val CONF_eth1_IP` $eth1name $shortname"
  9563.     fi
  9564.     if [ -n "$tr0name" ]; then
  9565.         shortname="`echo $tr0name | cut -d'.' -f 1`"
  9566.         tr0Line="`Get_Val CONF_tr0_IP` $tr0name $shortname"
  9567.     fi
  9568.     if [ "$fqhn" != "$nodename" ]; then
  9569.         shortname="$nodename"
  9570.     fi
  9571.     if [ -z "${eth0name}${eth1name}${tr0name}" ]; then
  9572.         LocalhostLine="127.0.0.1 $fqhn $shortname localhost"
  9573.     else
  9574.         LocalhostLine="127.0.0.1 localhost"
  9575.     fi
  9576.  
  9577.     # we don't prefix it with $DIR_TARGET as we copy it later
  9578.  
  9579.     Do_Backup_File $FILE_ETC_HOSTS
  9580.  
  9581.     cat << EOF > $FILE_ETC_HOSTS
  9582. # $FILE_ETC_HOSTS -  hostname_to_address mappings for the resolver library
  9583. #
  9584. # The format is:
  9585. #
  9586. # ipaddr fully_qualified_hostname list_of_nicknames
  9587. #
  9588. # We strongly recommend to use a fully qualified hostname for your machine
  9589. # if it is connected to any type of network. You can add short nicknames as
  9590. # you like, but the official canonical name is the name that follows the
  9591. # IP address and should always be a fully qualified hostname.
  9592. #
  9593. # If you don't have any network interfaces, you should put your hostname
  9594. # in the line of your loopback device, which has the address 127.0.0.1.
  9595. #
  9596. # LISA will automatically put the hostname in the right line for you.
  9597. #
  9598. #
  9599. # !!! Automatically generated by LISA from /etc/system.cnf. Do not edit !!!
  9600. #
  9601. # The loopback device. It should always be available.
  9602. #
  9603. $LocalhostLine
  9604. #
  9605. # Your first IP interface (if you are connected to any kind of network)
  9606. #
  9607. $eth0Line
  9608. $tr0Line
  9609. #
  9610. # Your second IP interface (normally for routers only)
  9611. #
  9612. $eth1Line
  9613. #
  9614. # If you have a nameserver we recommend to use it instead of putting many
  9615. # hosts in this file. If you don't have a nameserver though, you can add
  9616. # hostnames and their IP addresses below this line.
  9617. #
  9618. #===========================================================================
  9619. EOF
  9620.     chmod 644 $FILE_ETC_HOSTS
  9621.     if [ -f ${FILE_ETC_HOSTS}~ ]; then
  9622.         sed -n '/^#====/,${
  9623.             /^#====/d
  9624.             p
  9625.         }' ${FILE_ETC_HOSTS}~ >> $FILE_ETC_HOSTS
  9626.     fi
  9627. }
  9628.  
  9629. List_HOSTS()
  9630. {
  9631.   cat $FILE_ETC_HOSTS | sed '{
  9632.     /^#/d
  9633.     /^$/d
  9634.   }'
  9635. }
  9636.  
  9637. Build_HOSTS()
  9638. {
  9639.   List_HOSTS | do_quote
  9640. }
  9641.  
  9642. Menu_Hosts_Show()
  9643. {
  9644.   List_HOSTS > $FILE_TMP_MSG
  9645.   Browse2 $FILE_TMP_MSG HOSTS || return 1
  9646. }
  9647.  
  9648. Menu_Hosts_Add()
  9649. {
  9650.     local ipaddr=
  9651.     local fqhn=
  9652.     local nickname=
  9653.  
  9654.     while [ 1 ]; do
  9655.         Ask_IP HOST_ADD "$ipaddr" || return 1
  9656.         ipaddr="$ANSWER"
  9657.         sed -n "/^$ipaddr /p" $FILE_ETC_HOSTS > $FILE_TMP_ERR
  9658.         if [ -s $FILE_TMP_ERR ]; then
  9659.             Error --file $FILE_TMP_ERR ":ERR_IP_CONFLICT:"
  9660.             continue
  9661.         fi
  9662.         Ask_String HOST_ADD || continue
  9663.         fqhn="$ANSWER"
  9664.         sed -n "/ $fqhn$/p" $FILE_ETC_HOSTS > $FILE_TMP_ERR
  9665.         sed -n "/ $fqhn /p" $FILE_ETC_HOSTS >> $FILE_TMP_ERR
  9666.         if [ -s $FILE_TMP_ERR ]; then
  9667.             Error --file $FILE_TMP_ERR ":ERR_HOSTNAME_CONFLICT:"
  9668.             continue
  9669.         fi
  9670.         $CMD_BOX --title ":ASK_HOST_ADD_TITLE:" --string ":ASK_HOST_ADD_NICKNAME:" 2> $FILE_TMP_ANSWER || continue
  9671.         nickname="`cat $FILE_TMP_ANSWER`"
  9672.         sed -n "/ $nickname$/p" $FILE_ETC_HOSTS > $FILE_TMP_ERR
  9673.         sed -n "/ $nickname /p" $FILE_ETC_HOSTS >> $FILE_TMP_ERR
  9674.         if [ -s $FILE_TMP_ERR ]; then
  9675.             Error --file $FILE_TMP_ERR ":ERR_NICKNAME_CONFLICT:"
  9676.             continue
  9677.         fi
  9678.         echo "$ipaddr $fqhn $nickname" >> $FILE_ETC_HOSTS
  9679.         return 0
  9680.     done
  9681. }
  9682.  
  9683. Menu_Hosts_Del()
  9684. {
  9685.     Choose --menutitle ":INFO_HOSTS_MENUTITLE:" --build Build_HOSTS HOST_DEL || return 1
  9686.     if [ -z "$ANSWER" ]; then
  9687.         Error "no host specified"
  9688.         return 1
  9689.     fi
  9690.     if [ "$ANSWER" = "127.0.0.1" ]; then
  9691.         Warn ":WARN_KEEP_LOCALHOST:"
  9692.         return 0
  9693.     fi
  9694.     if [ "$ANSWER" = "`Get_Val CONF_eth0_IP`" ]; then
  9695.         Warn ":WARN_KEEP_YOUR_IP:"
  9696.         return 0
  9697.     fi
  9698.     sed "/^$ANSWER/d" $FILE_ETC_HOSTS > $FILE_ETC_HOSTS.tmp
  9699.     mv $FILE_ETC_HOSTS.tmp $FILE_ETC_HOSTS
  9700.     return 0
  9701. }
  9702.  
  9703. Menu_Config_Hosts()
  9704. {
  9705.     local=item
  9706.     while [ 1 ]; do
  9707.         if [ -z "$item" ]; then item="Menu_Hosts_Show" ; fi
  9708.         $CMD_BOX --help ":MENU_CONFIG_HOSTS_HELP:" \
  9709. --default "$item" \
  9710. --title ":MENU_CONFIG_HOSTS_TITLE:" \
  9711. --menu ":MENU_CONFIG_HOSTS_TEXT:" \
  9712. "Menu_Hosts_Show" ":MENU_HOSTS_SHOW:" \
  9713. "Menu_Hosts_Add" ":MENU_HOSTS_ADD:" \
  9714. "Menu_Hosts_Del" ":MENU_HOSTS_DEL:" 2> $FILE_TMP_ANSWER || break
  9715.         COMMAND="`cat $FILE_TMP_ANSWER`"
  9716.         item="$COMMAND"
  9717.         $COMMAND 
  9718.     done
  9719.     return 0
  9720. }
  9721.  
  9722.  
  9723. Do_Setup_NIS_glibc()
  9724. {
  9725.     local domain="`Get_Val CONF_NIS_DOMAIN`"
  9726.     local server1="`Get_Val CONF_NIS_SERVER1_IP`"
  9727.     local server2="`Get_Val CONF_NIS_SERVER2_IP`"
  9728.     local server3="`Get_Val CONF_NIS_SERVER3_IP`"
  9729.  
  9730.     local DomainLine=
  9731.     local Server1Line=
  9732.     local Server2Line=
  9733.     local Server3Line=
  9734.  
  9735.     if [ -n "$domain" ]; then
  9736.         DomainLine="domain $domain"
  9737.         domainname $domain
  9738.     fi
  9739.     if [ -n "$server1" ]; then
  9740.         Server1Line="$DomainLine server $server1"
  9741.     else
  9742.         Server1Line="$DomainLine broadcast"
  9743.     fi
  9744.     if [ -n "$server2" ]; then
  9745.         Server2Line="ypserver $server2"
  9746.     fi
  9747.     if [ -n "$server3" ]; then
  9748.         Server3Line="ypserver $server3"
  9749.     fi
  9750.  
  9751.     cat << EOF > $DIR_TARGET$FILE_NIS_CONF
  9752. # $FILE_NIS_CONF - NIS setup file
  9753. #
  9754. # possible entries are:
  9755. #
  9756. #    domain <domain> broadcast    This is the default NIS domain;
  9757. #                    Broadcasts are used to find an
  9758. #                    eligible server (insecure).
  9759. #        alternatively
  9760. #
  9761. #    domain <domain> server <ip>    Additionally specify which host
  9762. #                    to contact for NIS service.
  9763. #
  9764. #    ypserver <ip>            Fall-Back servers for NIS can
  9765. #                    be added this way for the case
  9766. #                    that the primary server is down.
  9767. #
  9768. # !!! This file may be automatically regenerated by LISA from
  9769. # /etc/system.cnf. Edit at your own risk !!!
  9770. #
  9771. $Server1Line
  9772. $Server2Line
  9773. $Server3Line
  9774. EOF
  9775.     chmod 644 $DIR_TARGET$FILE_NIS_CONF
  9776.     # filter out NIS lines from passwd and group
  9777.     sed '/^\+/d' $DIR_TARGET$FILE_ETC_PASSWD > $DIR_TARGET$FILE_ETC_PASSWD.tmp
  9778.     sed '/^\+/d' $DIR_TARGET$FILE_ETC_GROUP > $DIR_TARGET$FILE_ETC_GROUP.tmp
  9779.     if [ -n "$domain" ]; then
  9780.         # add NIS lines to passwd and group if NIS domain set
  9781.         echo "+::::::"     >> $DIR_TARGET$FILE_ETC_PASSWD.tmp
  9782.         echo "+:::"     >> $DIR_TARGET$FILE_ETC_GROUP.tmp
  9783.     fi
  9784.     chmod 644 $DIR_TARGET$FILE_ETC_PASSWD.tmp
  9785.     chmod 644 $DIR_TARGET$FILE_ETC_GROUP.tmp
  9786.     mv $DIR_TARGET$FILE_ETC_PASSWD.tmp $DIR_TARGET$FILE_ETC_PASSWD
  9787.     mv $DIR_TARGET$FILE_ETC_GROUP.tmp $DIR_TARGET$FILE_ETC_GROUP
  9788. }
  9789.  
  9790. Menu_Config_NIS()
  9791. {
  9792.     local dir_daemons=$DIR_TARGET/etc/sysconfig/daemons
  9793.     local num
  9794.     local retry
  9795.     local none_flag
  9796.     local nisdomain="`Get_Val CONF_NIS_DOMAIN`"
  9797.     local server1="`Get_Val CONF_NIS_SERVER1_IP`"
  9798.     local server2="`Get_Val CONF_NIS_SERVER2_IP`"
  9799.     local server3="`Get_Val CONF_NIS_SERVER3_IP`"
  9800.     local ip=
  9801.     local nissetup
  9802.  
  9803.     # try to find a good default value
  9804.     if [ -n "$nisdomain" ]; then
  9805.         # We do not really configure a NIS server, so default to CLIENT
  9806.         #if [ -n "$server1$server2$server3" ]; then
  9807.             nissetup=CLIENT
  9808.         #else
  9809.         #    nissetup=SERVER
  9810.         #fi
  9811.     else
  9812.         nissetup=NONE
  9813.     fi
  9814.  
  9815.     while [ 1 ]; do
  9816.         retry=
  9817.         none_flag=
  9818.         Choose --none NIS $nissetup || return 1
  9819.         nissetup="$ANSWER"
  9820.         if [ -z "$nissetup" ]; then
  9821.             nisdomain=
  9822.             server1=
  9823.             server2=
  9824.             server3=
  9825.             # disable nis server autostart
  9826.             Do_Setup_Daemon nis-server no
  9827.             break
  9828.         fi
  9829.         Ask_String NIS_DOMAIN $nisdomain || continue
  9830.         nisdomain="$ANSWER"
  9831.  
  9832.         case $nissetup in
  9833.         SERVER)
  9834.             # we are NIS server and client.
  9835.             server1=127.0.0.1
  9836.             # enable nis server autostart
  9837.             Do_Setup_Daemon nis-server yes
  9838.             ;;
  9839.         CLIENT)
  9840.             # We are a NIS client. Ask for IP addr of NIS servers.
  9841.             for num in 1 2 3 ; do
  9842.                 if [ $num -gt 1 ]; then none_flag='--none' ; fi
  9843.                 none_flag='--none'
  9844.                 Ask_IP $none_flag --pretext "NIS server $num ; " --help ":HELP_NIS_SERVER: :HELP_IP:" --num $num NIS_SERVER 
  9845.                 if [ $? -ne 0 ]; then retry=true ; break ; fi
  9846.                 if [ -z "$ANSWER" ]; then break ; fi
  9847.                 eval "`echo \"server$num=$ANSWER\"`"
  9848.             done
  9849.             # disable nis server autostart
  9850.             Do_Setup_Daemon nis-server no
  9851.             if [ -f $dir_daemons/nis-client ]; then
  9852.                 Do_Setup_Daemon nis-client yes
  9853.             fi
  9854.             ;;
  9855.         esac
  9856.         if [ -n "$retry" ]; then continue ; fi
  9857.         break
  9858.     done
  9859.     Do_Store CONF_NIS_DOMAIN "$nisdomain"
  9860.     Do_Store CONF_NIS_SERVER1_IP "$server1"
  9861.     Do_Store CONF_NIS_SERVER2_IP "$server2"
  9862.     Do_Store CONF_NIS_SERVER3_IP "$server3"
  9863.     Do_Setup_NIS_glibc
  9864.     return 0
  9865. }
  9866.  
  9867. Menu_Config_Router()
  9868. {
  9869.     local first_install=
  9870.     local defval=
  9871.     local v=CONF_ROUTER1_IP
  9872.     local r_ip="`Get_Val $v`"
  9873.     local my_net="`Get_Val CONF_eth0_NET`"
  9874.     local prefix=
  9875.     local suffix=
  9876.  
  9877.     if [ $# -gt 0 -a "$1" = "first" ]; then
  9878.         first_install=true
  9879.         shift 1
  9880.     fi
  9881.  
  9882.     if [ -n "$r_ip" -o -n "$first_install" ]; then
  9883.         defval=j
  9884.     else
  9885.         defval=n
  9886.     fi
  9887.  
  9888.     Ask_Bool ROUTER $defval
  9889.     if [ "$ANSWER" = "1" ]; then
  9890.         Do_Store $v ""
  9891.         return 0
  9892.     fi
  9893.  
  9894.     if [ -z "$r_ip" ]; then
  9895.         # try to make a good suggestion for the Router IP
  9896.         if [ -n "$my_net" ]; then
  9897.             prefix="`echo $my_net | cut -d'.' -f 1-3`"
  9898.             suffix="`echo $my_net | cut -d'.' -f 4`"
  9899.             suffix="`do_calc $suffix + 1`"
  9900.             r_ip="${prefix}.${suffix}"
  9901.         fi
  9902.     fi
  9903.  
  9904.     Ask_IP ROUTER $r_ip || return 1
  9905.     r_ip="$ANSWER"
  9906.  
  9907.     Do_Store $v "$r_ip"
  9908.     Set_ifcfg eth0
  9909.     if [ -n "$r_ip" ]; then
  9910.         Do_Ifcfg default up
  9911.     fi
  9912.     return 0
  9913. }
  9914.  
  9915. Ask_HOST()
  9916. {
  9917.     local num=
  9918.     if [ $# -gt 1 -a "$1" = "--num" ]; then
  9919.         num="--num $2"
  9920.         shift 2
  9921.     fi
  9922.     Ask_IP $num $1 || return 1
  9923.     return 0
  9924. }
  9925.  
  9926. Get_Supported_MTAs()
  9927. {
  9928.     # FIXME: this should be global and defined in /etc/lst.cnf
  9929.     local supported="sendmail smail qmail"
  9930.  
  9931.     echo $supported
  9932. }
  9933.  
  9934. Check_MTA_Available()
  9935. {
  9936.     if [ -f $DIR_TARGET/etc/mta/options/$1 ]; then
  9937.         return 0
  9938.     else
  9939.         return 1
  9940.     fi
  9941. }
  9942.  
  9943. Build_MTA()
  9944. {
  9945.     local i
  9946.  
  9947.     for i in `Get_Supported_MTAs` ; do
  9948.         Check_MTA_Available $i || continue
  9949.         echo "\"$i\" \"Mail Transfer Agent ($i)\" \\"
  9950.     done
  9951. }
  9952.  
  9953. Do_Setup_MTA()
  9954. {
  9955.     local mta_new="$1"
  9956.     local mta_old=
  9957.     local mta_switch_cmd=$DIR_TARGET/usr/sbin/mta-switch
  9958.     local suffix=
  9959.  
  9960.     if [ "$DIR_TARGET" != "/" ]; then
  9961.         suffix='-norun'
  9962.     fi
  9963.  
  9964.     if [ ! -f $mta_switch_cmd ]; then
  9965.         echo "$mta_switch_cmd : file not found" > $FILE_TMP_ERR
  9966.         return 1
  9967.     fi
  9968.  
  9969.     mta_old="`$mta_switch_cmd query`"
  9970.  
  9971.     # turn off any MTA we had before
  9972.     if [ -n "$mta_old" -a "$mta_old" != "none" ]; then
  9973.         $mta_switch_cmd off${suffix} 2> $FILE_TMP_ERR || return 1
  9974.     fi
  9975.  
  9976.     # turn on new MTA
  9977.     $mta_switch_cmd --${mta_new} on${suffix} 2> $FILE_TMP_ERR || return 1
  9978.     rm -f $FILE_TMP_ERR
  9979.     return 0
  9980. }
  9981.  
  9982. Choose_MTA()
  9983. {
  9984.     local last_mta
  9985.  
  9986.     while [ 1 ]; do
  9987.         if [ -f /etc/sysconfig/daemons/mta ]; then
  9988.             last_mta="`get_val -f /etc/sysconfig/daemons/mta VARIANT`"
  9989.         fi
  9990.         Choose --build Build_MTA MTA $last_mta || return 1
  9991.         Do_Setup_MTA $ANSWER && break
  9992.         Error --file $FILE_TMP_ERR
  9993.     done
  9994.     return 0
  9995. }
  9996.  
  9997. Menu_Config_Net_Services()
  9998. {
  9999.     local i
  10000.     local mta_cmd="Choose_MTA"
  10001.     local mta_label=":CHOOSE_MTA:"
  10002.     local mta_active=false
  10003.  
  10004.     # we like dynamic menues ;-)
  10005.     for i in `Get_Supported_MTAs` ; do
  10006.         Check_MTA_Available $i || continue
  10007.         mta_active=true
  10008.     done
  10009.  
  10010.     if [ "$mta_active" = "false" ]; then
  10011.         mta_cmd=
  10012.         mta_label=
  10013.     fi
  10014.  
  10015.     # those should be handled similar
  10016.     # "Menu_Config_Mail" ":MENU_CONFIG_MAIL:"
  10017.     # "Menu_Config_News" ":MENU_CONFIG_NEWS:"
  10018.  
  10019.     while [ 1 ]; do
  10020.         $CMD_BOX --help ":MENU_CONFIG_NET_SERVICES_HELP:" \
  10021.         --title ":MENU_CONFIG_NET_SERVICES_TITLE:" \
  10022.         --menu ":MENU_CONFIG_NET_SERVICES_TEXT:" \
  10023.         "Menu_Config_DNS" ":MENU_CONFIG_DNS:" \
  10024.         "Menu_Config_NIS" ":MENU_CONFIG_NIS:" \
  10025.         $mta_cmd $mta_label 2> $FILE_TMP_ANSWER || break
  10026.         case $? in
  10027.         0)
  10028.             COMMAND="`cat $FILE_TMP_ANSWER`"
  10029.             $COMMAND ;;
  10030.         1)
  10031.             break ;;
  10032.         esac
  10033.     done
  10034. }
  10035.  
  10036.  
  10037. Menu_Config_Net()
  10038. {
  10039.   local=item
  10040.   while [ 1 ]; do
  10041.     if [ -z "$item" ]; then item="Menu_Config_Net_Services" ; fi
  10042.     $CMD_BOX --help ":MENU_CONFIG_NET_HELP:" \
  10043. --default "$item" \
  10044. --title ":MENU_CONFIG_NET_TITLE:" \
  10045. --menu ":MENU_CONFIG_NET_TEXT:" \
  10046. "Menu_Config_Hosts" ":MENU_CONFIG_HOSTS:" \
  10047. "Menu_Config_Net_Connect" ":MENU_CONFIG_NET_CONNECT:" \
  10048. "Menu_Config_Net_Services" ":MENU_CONFIG_NET_SERVICES:" 2> $FILE_TMP_ANSWER || break
  10049.     COMMAND="`cat $FILE_TMP_ANSWER`"
  10050.     item="$COMMAND"
  10051.     $COMMAND
  10052.   done
  10053.   return 0
  10054. }
  10055.  
  10056. Prepare_SMB_Install()
  10057. {
  10058.     Info "Switching to SMB install mode (BETA)"
  10059.     sleep 5
  10060.     MountModulesFloppy || return 1
  10061.     while [ 1 ]; do
  10062.         Do_Load_Module_mini --silent smbfs "" || break
  10063.         if [ ! -f /floppy/usr/bin/smbmount.gz ]; then break ; fi
  10064.         cp -a /floppy/usr/bin/smbmount.gz /usr/bin || break
  10065.         gunzip /usr/bin/smbmount.gz || break
  10066.         return 0
  10067.     done
  10068.     umount /floppy
  10069.     Msg "Problems with smbfs or smbmount. SMB install not possible."
  10070.     return 1
  10071. }
  10072.  
  10073. Menu_Mount_NFS()
  10074. {
  10075.   local nfsserver="$1"
  10076.   local mountdir="$2"
  10077.   local nfspath="$3"
  10078.   local smbuser="Administrator"
  10079.   local netbiosname=""
  10080.  
  10081.   export ANSWER=
  10082.   while [ 1 ]; do
  10083.     Ask_String INSTALL_PATH_SRC $nfspath || return 1
  10084.     nfspath="$ANSWER"
  10085.     if [ -z "$mountdir" ]; then
  10086.       Ask_String MOUNT_TARGET_DIR || continue 
  10087.     fi
  10088.     if [ "`echo $nfspath | cut -c1,2`" = '//' ]; then
  10089.     # Dirty hack to support SMB installs
  10090.     Prepare_SMB_Install
  10091.     netbiosname="`echo $nfspath | cut -d'/' -f 3`"
  10092.     $CMD_BOX --string "SMB login name" --default "$smbuser" 2> $FILE_TMP_ANSWER || continue
  10093.     smbuser="`cat $FILE_TMP_ANSWER`"
  10094.     echo "$nfsserver $netbiosname" >> /etc/hosts
  10095.     if [ -n "$smbuser" ]; then
  10096.         reset 2>&1
  10097.         Do_Clear_Screen
  10098.         echo "smbmount $nfspath /mnt -I $nfsserver -U $smbuser"
  10099.         smbmount $nfspath /mnt -I $nfsserver -U $smbuser 2>&1
  10100.         if [ $? -eq 0 ]; then break ; fi
  10101.     else
  10102.         smbmount $nfspath /mnt -I $nfsserver -n && break
  10103.     fi
  10104.     echo -n "smbmount failed. press <return> to continue."
  10105.     read ans
  10106.     # cleanup /etc/hosts if the mount failed
  10107.     sed "/^${nfsserver} ${netbiosname}$/d" /etc/hosts > /etc/hosts.tmp
  10108.     mv /etc/hosts.tmp /etc/hosts
  10109.     else
  10110.         Do_Mount -o ro "${nfsserver}:${nfspath}" $mountdir && break
  10111.     fi
  10112.   done
  10113.   export ANSWER="${nfspath}"
  10114.   return 0
  10115. }
  10116.  
  10117. Show_Net_Info()
  10118. {
  10119.   Get_Net_Info > $FILE_TMP_MSG
  10120.   Browse2 $FILE_TMP_MSG ANALYSE || return 1
  10121.   return 0
  10122. }
  10123.  
  10124. # libLSTpkg - package handling library shared between several scripts
  10125. #
  10126. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  10127. #
  10128.  
  10129. Build_SERIES()
  10130. {
  10131.   Do_Calc_Freespace $DIR_TARGET
  10132.  
  10133.   touch $FILE_PKGS_SEL
  10134.   build_menu -U $FREESPACE -f -t $FILE_PKGS_SEL -d $FILE_PKGS_DATA
  10135. }
  10136.  
  10137. Get_Dependend_Pkgs()
  10138. {
  10139.   local preset=$1
  10140.  
  10141.   Debug "add dependend pkgs for $preset"
  10142.  
  10143.   # add pcmcia where necessary
  10144.   case $preset in
  10145.   min|minx|small)
  10146.     if [ -n "`sed -n '/^pcmcia_core/p' /proc/modules`" ]; then
  10147.       echo "pcmcia-cs"
  10148.     fi
  10149.     ;;
  10150.   esac
  10151. }
  10152.  
  10153. Get_Preset_Pkgs()
  10154. {
  10155.   local preset=$1
  10156.   local preset_file=/floppy/usr/lib/LST/pkgs.$preset.gz
  10157.   local series
  10158.  
  10159.   Debug "generate preset pkgs for $preset"
  10160.  
  10161.   if [ "$CND10_MODE" = "true" ]; then
  10162.     # use fixed preset file
  10163.     if [ -r $preset_file ]; then
  10164.       gzip -dfcv < $preset_file | sed '/^#/d'
  10165.     else
  10166.       Debug "preset file $preset not found. Use all."
  10167.       build_menu -n -p ":1:" -d $FILE_PKGS_DATA
  10168.     fi
  10169.   else
  10170.     case $preset in
  10171.     all|fileprintserver|minimum|minimumserver|networkserver|recommended|webserver)
  10172.       preset_file=/mnt/install/col/data/pkgs-0*${preset}.generic
  10173.       if [ -f $preset_file ]; then
  10174.     # FIXME: ugly hack to filter out version numbers (XFree86)
  10175.     sed 's/-[0123456789.]*$//' $preset_file > /tmp/mypkgs
  10176.     build_menu -t /tmp/mypkgs -n -p ":1:" -d $FILE_PKGS_DATA
  10177.       elif [ "$preset" = "all" ]; then
  10178.     build_menu -n -p ":1:" -d $FILE_PKGS_DATA
  10179.       else
  10180.     return 1
  10181.       fi
  10182.       ;;
  10183.     min)
  10184.       # only default packages of series basis and network
  10185.       for series in basis network ; do
  10186.     build_menu -n -c 1 -s $series -m ":2:j:" -p ":1:" -d $FILE_PKGS_DATA
  10187.       done
  10188.       ;;
  10189.     minx)
  10190.       # only default packages of series basis, network, xbasis and xappl
  10191.       for series in basis network xbasis xappl ; do
  10192.     build_menu -n -c 1 -s $series -m ":2:j:" -p ":1:" -d $FILE_PKGS_DATA
  10193.       done
  10194.       ;;
  10195.     small)
  10196.       # only default of all series
  10197.       for series in basis develop doku network tex text xappl xbasis xdevelo xemacs xextra xview ; do
  10198.     build_menu -n -c 1 -s $series -m ":2:j:" -p ":1:" -d $FILE_PKGS_DATA
  10199.       done
  10200.       ;;
  10201.     rec)
  10202.       # all pkgs of series basis
  10203.       for series in basis ; do
  10204.     build_menu -n -s $series -p ":1:" -d $FILE_PKGS_DATA
  10205.       done
  10206.  
  10207.       # all pkgs of series xbasis but no X servers
  10208.       sed '/^XSERV:/d' $FILE_PKGS_DATA | build_menu -n -s xbasis -p ":1:"
  10209.  
  10210.       # rec pkgs of series text,doku,develop,misc,network,tex,xappl,xemacs,xview
  10211.       for series in develop doku misc network text tex xappl xemacs xview ; do
  10212.     build_menu -n -c 2 -s $series -m ":2:j:" -p ":1:" -d $FILE_PKGS_DATA
  10213.       done
  10214.       ;;
  10215.     sel)
  10216.       # expert's private choice ;-)
  10217.       build_menu -t /usr/lib/LST/pkgs.sel -n -p ":1:" -d $FILE_PKGS_DATA
  10218.       ;;
  10219.     esac
  10220.     Get_Dependend_Pkgs $preset
  10221.   fi
  10222. }
  10223.  
  10224. Get_Preset_Size()
  10225. {
  10226.   local preset=$1
  10227.   # we have an overhead of about 20% for inodes, administrative data etc.
  10228.   # current algorithm is (x MB + 2 MB) * 1.20
  10229.   local fudge_factor=20
  10230.   local approx_usage=
  10231.   local preset_file=/floppy/usr/lib/LST/pkgs.$preset.gz
  10232.  
  10233.   if [ "$CND10_MODE" = "true" ]; then
  10234.     if [ -r $preset_file ]; then
  10235.       # grep precalculated from preset file
  10236.       gzip -dfcv < $preset_file |
  10237.         sed -n 's/^#% NEEDSPACE: ([0-9][0-9]*) MB.*/\1/p'
  10238.     else
  10239.       echo "?"
  10240.     fi
  10241.   else
  10242.     # generate selection list depending on the preset type
  10243.     Get_Preset_Pkgs $preset > $FILE_PKGS_SEL
  10244.     Do_Calc_Needspace $FILE_PKGS_SEL
  10245.     approx_usage="`do_calc $NEEDSPACE \* $fudge_factor`"
  10246.     approx_usage="`do_calc $approx_usage / 100`"
  10247.     approx_usage="`do_calc $approx_usage \+ $NEEDSPACE`"
  10248.     do_calc $approx_usage / 1048576
  10249.   fi
  10250. }
  10251.  
  10252.  
  10253. Build_PKG_SELECT_PRESET()
  10254. {
  10255.     local preset="$1"
  10256.     local size="$2"
  10257.     local preset_file
  10258.  
  10259.     case $preset in
  10260.     sel)
  10261.         if [ ! -f /usr/lib/LST/pkgs.sel ]; then
  10262.             return 0
  10263.         fi
  10264.         ;;
  10265.     all|fileprintserver|minimum|minimumserver|networkserver|recommended|webserver)
  10266.         preset_file=/mnt/install/col/data/pkgs-0*${preset}.generic
  10267.         if [ ! -f $preset_file ]; then
  10268.             return 0
  10269.         fi
  10270.         ;;
  10271.     esac
  10272.     echo "\"Menu_Pkg_Select_Preset $preset\" \":MENU_PKG_SELECT_PRESET_${preset}: (min. $size MB)\" \\"
  10273. }
  10274.  
  10275.  
  10276. Build_PKG_SELECT()
  10277. {
  10278.     local size_spare="`do_calc $SPARESPACE / 1048576`"
  10279.     local size_data=
  10280.     local size=
  10281.     #local profiles="sel minimumserver webserver fileprintserver networkserver recommended rec minimum min minx small all" 
  10282.     local profiles="sel minimumserver webserver fileprintserver networkserver recommended minimum all" 
  10283.     local preset 
  10284.  
  10285.     if [ "$DIR_TARGET" != "/" ]; then
  10286.         for preset in $profiles ; do
  10287.             size_data="`Get_Preset_Size $preset`"
  10288.             size="`do_calc $size_data + $size_spare`"
  10289.             Build_PKG_SELECT_PRESET $preset $size
  10290.         done
  10291.     fi
  10292.     # offer customizable selection in expert mode
  10293.     Is_Expert
  10294.     if [ $? -eq 0 ]; then
  10295.         cat << EOF
  10296. "Menu_Pkg_Select_Services" ":MENU_PKG_SELECT_SERVICES:" \\
  10297. "Menu_Pkg_Select_Series" ":MENU_PKG_SELECT_SERIES:" \\
  10298. "Menu_Pkg_Select_Pkgs" ":MENU_PKG_SELECT_PKGS:" \\
  10299. EOF
  10300.     fi
  10301. }
  10302.  
  10303. Build_SELECT_PRIO()
  10304. {
  10305.   local statistics=
  10306.   local dummy=
  10307.   local pkgnum=
  10308.   local summin=
  10309.   local sumrec=
  10310.   local sumall=
  10311.   local sumsel=
  10312.  
  10313.   # Get statistics
  10314.   touch $FILE_PKGS_SEL
  10315.   touch $DIR_LST_TMP/$1.sel
  10316.   statistics="`build_menu -S -s $1 -T $DIR_LST_TMP/$1.sel -d $FILE_PKGS_DATA`"
  10317.  
  10318.   Debug "statistics for SERIES <$1> is <$statistics>"
  10319.  
  10320.   if [ -z "$statistics" ]; then
  10321.     cat << EOF
  10322. "1" ":TYPE_SEL_MIN:" \\
  10323. "2" ":TYPE_SEL_REC:" \\
  10324. "3" ":TYPE_SEL_ALL:" \\
  10325. "0" ":TYPE_SEL_NOT:" \\
  10326. EOF
  10327.   else
  10328.     IFS=':' read dummy dummy pkgnum summin sumrec sumall sumsel dummy << EOF
  10329. $statistics
  10330. EOF
  10331.     cat << EOF
  10332. --menutitle ":CHOOSE_SELECT_PRIO_MENUTITLE: $1 ($pkgnum :PKGS:)" \\
  10333. EOF
  10334.     if [ -s $DIR_LST_TMP/$SERIES.sel -a "$sumsel" != "0" ]; then
  10335.       echo "\"4\" \":TYPE_SEL_LAST:\" \\"
  10336.     fi
  10337.     cat << EOF
  10338. "1" ":TYPE_SEL_MIN: ($summin kB)" \\
  10339. "2" ":TYPE_SEL_REC: ($sumrec kB)" \\
  10340. "3" ":TYPE_SEL_ALL: ($sumall kB)" \\
  10341. EOF
  10342.     echo "\"0\" \":TYPE_SEL_NOT:\" \\"
  10343.   fi
  10344. }
  10345.  
  10346. Build_INSTALL_MEDIUM()
  10347. {
  10348.   # "tape" ":TYPE_INSTALL_MEDIUM_TAPE:"
  10349.   # "slip" ":TYPE_INSTALL_MEDIUM_SLIP:" 
  10350.   if [ "$DIR_TARGET" = "/" ]; then
  10351.     cat << EOF
  10352. "path" ":TYPE_INSTALL_MEDIUM_PATH:" \\
  10353. EOF
  10354.   fi
  10355.   cat << EOF
  10356. "cdrom" ":TYPE_INSTALL_MEDIUM_CDROM:" \\
  10357. "harddisk" ":TYPE_INSTALL_MEDIUM_HARDDISK:" \\
  10358. "network" ":TYPE_INSTALL_MEDIUM_NETWORK:" \\
  10359. EOF
  10360. }
  10361.  
  10362. Build_PKG()
  10363. {
  10364.   touch /tmp/LST/HOPE
  10365.   cat /tmp/LST/HOPE
  10366.   rm -f /tmp/LST/HOPE
  10367. }
  10368.  
  10369. Build_PKG_Info()
  10370. {
  10371.   build_menu -f -d $FILE_PKGS_DATA
  10372. }
  10373.  
  10374. Build_PKG_Installed()
  10375. {
  10376.   build_menu -f -d $FILE_PKGS_DATA
  10377. }
  10378.  
  10379. Check_Pkg_Database()
  10380. {
  10381.   if [ -z "$FILE_PKGS_DATA" ]; then
  10382.     Msg ":ERR_MISSING_PKG_DATABASE_FILE_NAME:"
  10383.     return 1        
  10384.   fi
  10385.   if [ ! -f "$FILE_PKGS_DATA" ]; then
  10386.     Msg ":ERR_MISSING_PKG_DATABASE:"
  10387.     return 1        
  10388.   fi
  10389.   return 0
  10390. }
  10391.  
  10392. Check_Pkg_Index()
  10393. {
  10394.   if [ -z "$FILE_PKGS_INDEX" ]; then
  10395.     Msg ":ERR_MISSING_PKG_INDEX_FILE_NAME:"
  10396.     return 1        
  10397.   fi
  10398.   if [ ! -f "$FILE_PKGS_INDEX" ]; then
  10399.     Msg ":ERR_MISSING_PKG_INDEX:"
  10400.     return 1        
  10401.   fi
  10402.   return 0
  10403. }
  10404.  
  10405. Choose_Install_Source()
  10406. {
  10407.     # If we run from the lisa live filesystem we use a simpler routine
  10408.     if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep text`" ]; then
  10409.         while [ 1 ]; do 
  10410.             rm -f /source
  10411.             if [ -n "`mount | fgrep /mnt/install | fgrep ':'`" ]; then
  10412.                 ANSWER="network"
  10413.             else
  10414.                 ANSWER="cdrom"
  10415.             fi
  10416.             CONF_INSTALL_MEDIUM="$ANSWER"
  10417.             Debug "CONF_INSTALL_MEDIUM=<$CONF_INSTALL_MEDIUM>"
  10418.             Do_Store CONF_INSTALL_MEDIUM "$CONF_INSTALL_MEDIUM"
  10419.             case $CONF_INSTALL_MEDIUM in
  10420.             network)
  10421.                 CONF_INSTALL_DEV="`mount | fgrep ' on /mnt/install ' | cut -d':' -f 1`"
  10422.                 Is_Known_Source /mnt/install || continue
  10423.                 ;;
  10424.             cdrom)
  10425.                 CONF_INSTALL_DEV="`mount | fgrep ' on /mnt/install ' | cut -d' ' -f 1`"
  10426.                 ln -sf $CONF_INSTALL_DEV /dev/cdrom
  10427.                 Is_Known_Source /mnt/install || continue
  10428.                 ;;
  10429.             esac
  10430.             ln -sf $DIR_SOURCE /source
  10431.             break
  10432.         done
  10433.         Do_Store CONF_INSTALL_DEV "$CONF_INSTALL_DEV"
  10434.         Do_Store CONF_INSTALL_PATH_SRC "$CONF_INSTALL_PATH_SRC"
  10435.         Do_Store DIR_SOURCE "$DIR_SOURCE"
  10436.         Do_Store DIR_PKGS "$DIR_PKGS"
  10437.         return 0
  10438.     else
  10439.   # FIXME: clean this mess up, also concerning FHS (/media el. al.)
  10440.   while [ 1 ]; do 
  10441.     rm -f /source
  10442.     Do_Umount /mnt || continue
  10443.     if [ "`get_val -f /etc/lst.cnf CONF_COL_EDITION`" = "SBA" ]; then
  10444.       ANSWER="cdrom"
  10445.     else
  10446.       Choose --build Build_INSTALL_MEDIUM INSTALL_SOURCE CONF_INSTALL_MEDIUM || return 1
  10447.     fi
  10448.     CONF_INSTALL_MEDIUM="$ANSWER"
  10449.     Debug "CONF_INSTALL_MEDIUM=<$CONF_INSTALL_MEDIUM>"
  10450.     Do_Store CONF_INSTALL_MEDIUM "$CONF_INSTALL_MEDIUM"
  10451.     Do_Umount /mnt || continue
  10452.     case $CONF_INSTALL_MEDIUM in
  10453.     path)
  10454.       CONF_INSTALL_DEV=path
  10455.       Ask_String DIR_SOURCE "/mnt" || continue
  10456.       Is_Known_Source $ANSWER || continue
  10457.       ;;
  10458.     floppy)
  10459.       Choose --other FLOPPY || continue
  10460.       CONF_INSTALL_DEV="`Get_Val CONF_FLOPPY${ANSWER}_DEV`"
  10461.       if [ -z "$CONF_INSTALL_DEV" ]; then
  10462.     CONF_INSTALL_DEV="/dev/fd0H1440"
  10463.       fi
  10464.       CONF_INSTALL_PATH_SRC=
  10465.       DIR_PKGS=/mnt
  10466.       ;;
  10467.     harddisk)
  10468.       Choose --menutitle ":CHOOSE_PARTITION_MENUTITLE:" --build "Build_PARTITION Src" PARTITION_SOURCE || continue
  10469.       CONF_INSTALL_DEV="$ANSWER"
  10470.       if [ -z "$CONF_INSTALL_DEV" ]; then continue ; fi
  10471.       Do_Mount -o ro $CONF_INSTALL_DEV /mnt || continue
  10472.       Is_Known_Source || continue
  10473.       ;;
  10474.     network|slip)
  10475.       # FIXME
  10476.       Do_Load_Driver filesystem nfs || continue
  10477.       : > $FILE_TMP_ERR
  10478.       Menu_Config_Nethost first
  10479.       if [ "$?" != "0" ]; then
  10480.     Error --file $FILE_TMP_ERR "Unable to configure ethernet device."
  10481.     continue
  10482.       fi
  10483.       Ask_HOST --num 1 NFS_SERVER || continue
  10484.       CONF_INSTALL_DEV="$ANSWER"
  10485.       Do_Store CONF_NFS_SERVER1_IP "$ANSWER"
  10486.       CONF_NFS_SERVER1_PATH="`Get_Val CONF_NFS_SERVER1_PATH`"
  10487.       if [ -n "$CONF_NFS_SERVER1_PATH" ]; then
  10488.     CONF_INSTALL_PATH_SRC="$CONF_NFS_SERVER1_PATH"
  10489.       fi
  10490.       Menu_Mount_NFS $CONF_NFS_SERVER1_IP /mnt $CONF_INSTALL_PATH_SRC || continue
  10491.       CONF_INSTALL_PATH_SRC="$ANSWER"
  10492.       Debug "After NFS mount"
  10493.       Do_Store CONF_NFS_SERVER1_PATH "$ANSWER"
  10494.       Is_Known_Source || continue
  10495.       ;;
  10496.     cdrom)
  10497.       Menu_Config_CD || continue
  10498.       sleep 2
  10499.       CONF_INSTALL_DEV="$ANSWER"
  10500.       if [ -z "$CONF_INSTALL_DEV" ]; then continue ; fi    
  10501.       ln -sf $ANSWER /dev/cdrom
  10502.       Do_Mount -t iso9660 -o ro $CONF_INSTALL_DEV /mnt || continue
  10503.       Do_Analyse_CD || continue
  10504.       Is_Known_Source || continue
  10505.       ;;
  10506.     tape)
  10507.       Menu_Config_Tape || continue
  10508.       CONF_INSTALL_DEV="$ANSWER"
  10509.       if [ -z "$CONF_INSTALL_DEV" ]; then continue ; fi    
  10510.  
  10511.       # FIXME support tape installation
  10512.       Err_Not_Available
  10513.       continue
  10514.       CONF_INSTALL_PATH_SRC=
  10515.       DIR_PKGS=
  10516.       ;;
  10517.     esac
  10518.     ln -sf $DIR_SOURCE /source
  10519.     break
  10520.   done
  10521.   Do_Store CONF_INSTALL_DEV "$CONF_INSTALL_DEV"
  10522.   Do_Store CONF_INSTALL_PATH_SRC "$CONF_INSTALL_PATH_SRC"
  10523.   Do_Store DIR_SOURCE "$DIR_SOURCE"
  10524.   Do_Store DIR_PKGS "$DIR_PKGS"
  10525.   return 0
  10526.     fi
  10527. }
  10528.  
  10529. Do_Reverse()
  10530. {
  10531.     local rev_string=""
  10532.     local i
  10533.  
  10534.     if [ $# -eq 0 ]; then
  10535.         echo ""
  10536.         return 0
  10537.     fi
  10538.     for i in $@ ; do
  10539.         rev_string="$i $rev_string"
  10540.     done
  10541.     echo $rev_string
  10542.     return 0
  10543. }
  10544.  
  10545. Choose_Install_Target()
  10546. {
  10547.     local partition
  10548.     local mountpoint
  10549.     local dummy
  10550.     local root_mounted
  10551.     local root_last
  10552.     local root_conf
  10553.     local try_root
  10554.     local mke2fs_retval
  10555.     local devs_under_root=""
  10556.     local devs_under_root_rev=""
  10557.     local auto_target="`Get_Val CONF_INSTALL_ROOT`"
  10558.     local i
  10559.  
  10560.         rm -f $FILE_TARGETS_SEL
  10561.     while [ 1 ]; do
  10562.     partition=
  10563.     mountpoint=/root
  10564.     dummy=
  10565.     root_mounted=
  10566.     root_last=
  10567.     root_conf=
  10568.     try_root=
  10569.  
  10570.     Debug "Choose_Install_Target called."
  10571.     if [ -f /tmp/root.fix ]; then
  10572.         CONF_INSTALL_ROOT="`cat /tmp/root.fix`"
  10573.         DIR_TARGET="`Get_Val DIR_TARGET`"
  10574.     else
  10575.         # start of not indended area...
  10576.  
  10577.     # check whether we have any target partition at all
  10578.     if [ -z "`sysinfo -C Dest --notitle --noheader --partition`" ]; then
  10579.         Error2 NO_TARGET_AVAILABLE
  10580.         ANSWER="new"
  10581.         return 0
  10582.     fi
  10583.  
  10584.     # check whether there is something mounted on $mountpoint
  10585.     Check_Directory_Busy $mountpoint || root_mounted="$STATUS"
  10586.  
  10587.     CONF_INSTALL_ROOT=
  10588.     rm -f $FILE_ROOT_SEL.not
  10589.     touch $FILE_ROOT_SEL.not
  10590.     for i in $root_mounted $root_last $root_conf ; do
  10591.         cat $FILE_ROOT_SEL.not | fgrep -x "$i" >/dev/null && continue
  10592.         # ask whether we want to use this
  10593.         # FIXME: hardcoded strings
  10594.         $CMD_BOX --default "j" --bool "The partition $i ; :ASK_USE_AS_ROOT_PARTITION:" 2> $FILE_TMP_ANSWER || return 1
  10595.         if [ "`cat $FILE_TMP_ANSWER`" = "0" ]; then
  10596.             try_root="$i"
  10597.             break
  10598.         else
  10599.             echo "$i" >> $FILE_ROOT_SEL.not
  10600.         fi
  10601.     done
  10602.     rm -f $FILE_ROOT_SEL.not
  10603.  
  10604.     # first unmount any partitions below /root in reverse order
  10605.     devs_under_root="`mount | sed -n '/on \/root\//p' | cut -d' ' -f 1`"
  10606.     if [ -n "$devs_under_root" ]; then
  10607.         devs_under_root_rev="`Do_Reverse "$devs_under_root"`"
  10608.         if [ -n "$devs_under_root_rev" ]; then
  10609.             for i in $devs_under_root_rev ; do
  10610.                 Do_Umount $i
  10611.             done
  10612.         fi
  10613.     fi
  10614.  
  10615.     # unmount old partitions
  10616.     touch $FILE_TARGETS_SEL
  10617.     for i in `cat $FILE_TARGETS_SEL` ; do
  10618.         # do not unmount new root partition
  10619.         if [ "$i" = "$CONF_INSTALL_ROOT" ]; then
  10620.             continue
  10621.         fi
  10622.         # do not unmount source device
  10623.         if [ "$i" = "$CONF_INSTALL_DEV" ]; then
  10624.             continue
  10625.         fi
  10626.         # do not unmount swap partitions
  10627.         if [ -f $FILE_SWAP_SEL ]; then
  10628.             fgrep -x "$i" $FILE_SWAP_SEL >/dev/null
  10629.             if [ $? -eq 0 ]; then
  10630.                 continue
  10631.             fi
  10632.         fi
  10633.         Do_Umount $i
  10634.     done
  10635.  
  10636.     # ask for target root partition
  10637.     while [ 1 ]; do
  10638.         CONF_INSTALL_ROOT=
  10639.         if [ -n "$try_root" ]; then
  10640.             CONF_INSTALL_ROOT="$try_root"
  10641.             try_root=
  10642.             fs_type="`mount | sed -n '/on \/root /s/.*type \([^ ]*\) .*/\1/p'`"
  10643.             break
  10644.         else
  10645.             # umsdos source and target IMPOSSIBLE!
  10646.             Debug "FTS: appended '$CONF_INSTALL_DEV'"
  10647.             echo "$CONF_INSTALL_DEV" >> $FILE_TARGETS_SEL
  10648.             Choose --menutitle ":CHOOSE_PARTITION_MENUTITLE:" --build "Build_PARTITION --exclude $FILE_TARGETS_SEL DestSorted" PARTITION_ROOT $auto_target || return 1
  10649.             if [ -z "$ANSWER" ]; then
  10650.                 Error "no partition specified!"
  10651.                 continue
  10652.             else
  10653.                 CONF_INSTALL_ROOT="$ANSWER"
  10654.             fi
  10655.         fi
  10656.         partid="`Get_Partition_Info --id $CONF_INSTALL_ROOT`"
  10657.         if [ "$partid" = "1" -o "$partid" = "4" -o "$partid" = "6" ]; then
  10658.             Warn "Partition $CONF_INSTALL_ROOT ; :WARN_USE_UMSDOS:" || continue
  10659.             Do_Mount -t umsdos $CONF_INSTALL_ROOT /root || continue
  10660.             fs_type="$ANSWER"
  10661.             if [ "$fs_type" = "umsdos" ]; then
  10662.                 if [ -d /root/linux ]; then
  10663.                     Ask_Bool --pretext "Partition $CONF_INSTALL_ROOT ; " DELETE_LINUX_SUBDIR || return 1
  10664.                     if [ "$ANSWER" = "0" ]; then
  10665.                         rm -fr /root/linux
  10666.                     else
  10667.                         Warn "Partition $CONF_INSTALL_ROOT ; :WARN_NOT_USABLE_AS_ROOT:"
  10668.                         return 1
  10669.                     fi
  10670.                 fi
  10671.                 mkdir -p /root/linux/etc
  10672.                 touch /root/linux/etc/rc
  10673.                 prep_use UMSDOS
  10674.                 umssync -r99 -v- /root/linux >>$FILE_LOG_HISTORY 2>&1
  10675.                 end_use UMSDOS
  10676.                 DIR_TARGET=/root/linux
  10677.                 mkdir -p $DIR_TARGET/var/adm/LST/log
  10678.                 PATH=${PATH}:$DIR_TARGET/bin:$DIR_TARGET/usr/bin:$DIR_TARGET/sbin:$DIR_TARGET/usr/sbin
  10679.                 export PATH
  10680.                 break
  10681.             else
  10682.                 Error "DOS Partition was not mounted as type umsdos but as type $fs_type"
  10683.                 Do_Umount /root
  10684.                 continue
  10685.             fi
  10686.         elif [ "$partid" = "131" ]; then
  10687.             # do not format partitions that contain a swap file
  10688.             ROOT_INITIALIZED=0
  10689.             Check_Found "$CONF_INSTALL_ROOT" "$FILE_SWAP_SEL"
  10690.             if [ $? -ne 0 ]; then
  10691.                 # otherwise force format for root partition
  10692.                 Do_Umount $CONF_INSTALL_ROOT || continue
  10693.                 Do_Umount /root || continue
  10694.                 Menu_Call_Mke2fs "$CONF_INSTALL_ROOT" || continue
  10695.             fi
  10696.             Do_Mount -t ext2 $CONF_INSTALL_ROOT /root || continue
  10697.             fs_type="$ANSWER"
  10698.             DIR_TARGET=/root
  10699.             mkdir -p $DIR_TARGET/var/adm/LST/log
  10700.             break
  10701.         else
  10702.             Error "a partition with type <$partid> can not be used as root-partition!"
  10703.             continue
  10704.         fi
  10705.     done
  10706.     Debug "FTS: appending '$CONF_INSTALL_ROOT'"
  10707.     echo "$CONF_INSTALL_ROOT" >> $FILE_TARGETS_SEL
  10708.     echo "$CONF_INSTALL_ROOT" > $FILE_ROOT_SEL
  10709.     # we don't need to ask for a mount point here as it's implicit for root
  10710.     mkdir -p $DIR_TARGET/proc
  10711.     mkdir -p $DIR_TARGET/etc    
  10712.     echo "$CONF_INSTALL_ROOT / $fs_type defaults 0 1" > $DIR_TARGET/etc/fstab
  10713.     echo "/proc /proc proc defaults 0 0" >> $DIR_TARGET/etc/fstab
  10714.     if [ -s $FILE_SWAP_SEL ]; then
  10715.         if [ -s /tmp/fstab.tmp ]; then
  10716.             cat /tmp/fstab.tmp >> $DIR_TARGET/etc/fstab
  10717.         else
  10718.             echo "`cat $FILE_SWAP_SEL` none swap defaults 0 0" >> $DIR_TARGET/etc/fstab
  10719.         fi
  10720.         Debug "FTS: appending '$FILE_SWAP_SEL'"
  10721.         cat $FILE_SWAP_SEL >> $FILE_TARGETS_SEL
  10722.     fi
  10723.     chmod 644 $DIR_TARGET/etc/fstab
  10724.  
  10725.         # end of not indended area
  10726.     fi
  10727.     Do_Store CONF_INSTALL_ROOT "$CONF_INSTALL_ROOT"
  10728.     Do_Store DIR_TARGET "$DIR_TARGET"
  10729.  
  10730.     # ask for additional target partitions
  10731.     while [ 1 ]; do
  10732.         if [ -z "`Build_PARTITION --exclude $FILE_TARGETS_SEL Linux`" ];then
  10733.             Debug --diskonly "No ADDITIONAL partitions available"
  10734.             return 0
  10735.         fi
  10736.         Ask_Bool MORE_TARGET_PARTITIONS n || break
  10737.         if [ "$ANSWER" = "1" ]; then
  10738.             return 0
  10739.         fi
  10740.         Choose --menutitle ":CHOOSE_PARTITION_MENUTITLE:" --build "Build_PARTITION --exclude $FILE_TARGETS_SEL Linux" PARTITION_OTHER
  10741.         if [ -z "$ANSWER" ]; then
  10742.             Error "no partition specified!"
  10743.             continue
  10744.         elif [ "$ANSWER" = "new" ]; then
  10745.             return 0
  10746.         else
  10747.             partition="$ANSWER"
  10748.         fi
  10749.         while [ 1 ]; do
  10750.             Ask_String MOUNTPOINT || continue
  10751.             if [ -n "$ANSWER" ]; then
  10752.                 # make PATH absolute
  10753.                 echo "$ANSWER" | cut -c 1 | fgrep '/' >/dev/null || ANSWER="/$ANSWER"
  10754.                 break
  10755.             else
  10756.                 Error "no mount point specified"
  10757.             fi
  10758.         done
  10759.         mountpoint="$ANSWER"
  10760.  
  10761.         partid="`Get_Partition_Info --id $partition`"
  10762.         if [ "$partid" = "131" ]; then
  10763.             Menu_Call_Mke2fs "$partition"
  10764.             mke2fs_retval=$?
  10765.             if [ $mke2fs_retval -eq 2 ] ; then
  10766.                 # we did not want to format it
  10767.                 # can we mount it?
  10768.                 mkdir -p /tmp/mnt
  10769.                 mount -r -t ext2 $partition /tmp/mnt >/dev/null 2>&1
  10770.                 if [ $? -eq 0 ]; then
  10771.                     umount /tmp/mnt >/dev/null 2>&1
  10772.                     Ask_Bool --pretext "Partition $partition ; " MOUNT_INSTEAD_FORMAT || continue
  10773.                     if [ "$ANSWER" = "0" ]; then
  10774.                         Warn ":WARN_PARTITION_NOT_FORMATED:" || continue
  10775.                     else
  10776.                         continue
  10777.                     fi
  10778.                 fi
  10779.             else
  10780.                 if [ $mke2fs_retval -ne 0 ] ; then continue ; fi
  10781.             fi
  10782.         fi
  10783.         mkdir -p ${DIR_TARGET}$mountpoint
  10784.         Do_Mount "$partition" ${DIR_TARGET}$mountpoint || continue
  10785.         fs_type="$ANSWER"
  10786.         echo "$partition" > $FILE_TARGETS_SEL.tmp
  10787.         if [ ! -f $FILE_TARGETS_SEL ]; then
  10788.             Panic "no root partition specified!"
  10789.             return 1
  10790.         fi
  10791.         cat $FILE_TARGETS_SEL >> $FILE_TARGETS_SEL.tmp
  10792.         mv $FILE_TARGETS_SEL.tmp $FILE_TARGETS_SEL
  10793.         Debug "FTS: setting '`cat $FILE_TARGETS_SEL`'"
  10794.         echo "$partition $mountpoint $fs_type defaults 0 2" >> $DIR_TARGET/etc/fstab
  10795.         mkdir -p $DIR_TARGET/var/adm/LST/log
  10796.       done # other choose loop
  10797.     done # target choose loop
  10798.     return 0
  10799. }
  10800.  
  10801. # checks if CD is valid and writes version to Debug
  10802. #
  10803. Do_Analyse_CD()
  10804. {
  10805.   local cd_label=
  10806.   local smarties_retval=
  10807.  
  10808.   if [ -x /usr/lib/LST/smarties ]; then
  10809.     /usr/lib/LST/smarties $CONF_INSTALL_DEV > /tmp/.version
  10810.     smarties_retval=$?
  10811.     cd_label="`cat /tmp/.version`"
  10812.  
  10813.     # continue if smarties has internal problems (driver errors on seek/read)
  10814.     if [ $smarties_retval -eq 3 ]; then
  10815.       return 0
  10816.     fi
  10817.  
  10818.     # abort if unknown CD was detected
  10819.     if [ -z "$cd_label" ]; then
  10820.       Debug "CDROM is unknown"
  10821.       #Do_Umount /mnt
  10822.       Error2 NO_ORIG_CD
  10823.       #Ask_Bool CONTINUE_INSTALL n
  10824.       #if [ "$ANSWER" = "0" ]; then
  10825.     return 0
  10826.       #fi
  10827.       #return 1
  10828.     else
  10829.       Debug "CDROM is <$cd_label>"
  10830.       if [ "`get_val -f /etc/lst.cnf CONF_COL_EDITION`" != "SBA" ]; then
  10831.         Msg ":INFO_KNOWN_CD_DETECTED: ; ; $cd_label"
  10832.         if [ "$cd_label" = "Toolbox Linux Sonderheft 1997" ]; then
  10833.           Msg ":INFO_TOOLBOX_CD:"
  10834.         fi
  10835.       fi
  10836.     fi
  10837.  
  10838.     # abort if a non install CD was inserted
  10839.     if [ $smarties_retval -ne 0 ]; then
  10840.       Debug "wrong CD inserted"
  10841.       Do_Umount /mnt
  10842.       Error2 NO_INSTALL_CD
  10843.       return 1
  10844.     else
  10845.       return 0
  10846.     fi
  10847.   fi
  10848. }
  10849.  
  10850. MountModulesFloppy()
  10851. {
  10852.   local modpath="/lib/modules"
  10853.   local success=
  10854.  
  10855.   mount /floppy >/dev/null 2>&1
  10856.   while [ 1 ]; do
  10857.     if [ -d /floppy/$modpath ]; then
  10858.       success=true
  10859.       break
  10860.     else
  10861.       umount /floppy >/dev/null 2>&1
  10862.       Msg ":DO_INSERT_MODULES_FLOPPY:" || break
  10863.       mount /floppy >/dev/null 2>&1
  10864.     fi
  10865.   done
  10866.   if [ -n "$success" ]; then
  10867.     return 0
  10868.   else
  10869.     return 1
  10870.   fi
  10871. }
  10872.  
  10873. # checks if source path is valid and sets
  10874. # CONF_INSTALL_PATH_SRC
  10875. # DIR_BIN
  10876. # DIR_DATA
  10877. # DIR_SOURCE
  10878. # DIR_PKGS
  10879. #
  10880. Is_Known_Source()
  10881. {
  10882.   local prefix="/mnt" # during install the source is mounted under /mnt
  10883.   local suffix="install/basis1/basis1.idx"
  10884.  
  10885.   if [ $# -gt 0 ]; then
  10886.     prefix="$1" # later we may specify a different path
  10887.   fi
  10888.  
  10889.   while [ 1 ]; do
  10890.     export DIR_BIN=
  10891.     export DIR_DATA=
  10892.     export DIR_PKGS=
  10893.  
  10894.     if [ -d $prefix/install -a -d $prefix/bin -a -d $prefix/data ]; then
  10895.       Debug "found Caldera OpenLinux / LST Power Linux"
  10896.       CONF_INSTALL_PATH_SRC=""
  10897.       DIR_SOURCE="$prefix"
  10898.       DIR_DATA="$DIR_SOURCE/data"
  10899.       DIR_BIN="$DIR_SOURCE/bin"
  10900.       DIR_PKGS="$DIR_SOURCE/install"
  10901.       return 0
  10902.     elif [ -f $prefix/live -a $prefix/col/data/cd1 ]; then
  10903.       Debug "found Caldera OpenLinux 2.x CD 1"
  10904.       CONF_INSTALL_PATH_SRC="col"
  10905.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  10906.       DIR_DATA="$DIR_SOURCE/data"
  10907.       if [ -f $DIR_DATA/pkgs.db ]; then
  10908.         cp -a $DIR_DATA/pkgs.db $FILE_PKGS_DATA
  10909.       fi
  10910.       if [ -f $DIR_DATA/us/pkgs.idx ]; then
  10911.         cp -a $DIR_DATA/us/pkgs.idx $FILE_PKGS_INDEX
  10912.       fi
  10913.       DIR_BIN="$DIR_SOURCE/bin"
  10914.       DIR_PKGS="$DIR_SOURCE/install"
  10915.       return 0
  10916.     elif [ -f $prefix/col/data/cd1 ]; then
  10917.       Debug "found Caldera OpenLinux 1.2 CD 1"
  10918.       CONF_INSTALL_PATH_SRC="col"
  10919.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  10920.       DIR_DATA="$DIR_SOURCE/data"
  10921.       if [ -f $DIR_DATA/pkgs.db ]; then
  10922.         cp -a $DIR_DATA/pkgs.db $FILE_PKGS_DATA
  10923.       fi
  10924.       DIR_BIN="$DIR_SOURCE/bin"
  10925.       DIR_PKGS="$DIR_SOURCE/install"
  10926.       return 0
  10927.     elif [ -f $prefix/col/data/cd2 ]; then
  10928.       Debug "found Caldera OpenLinux 1.2 CD 2"
  10929.       CONF_INSTALL_PATH_SRC="col"
  10930.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  10931.       DIR_DATA="$DIR_SOURCE/data"
  10932.       if [ -f $DIR_DATA/pkgs.db ]; then
  10933.         cp -a $DIR_DATA/pkgs.db $FILE_PKGS_DATA
  10934.       fi
  10935.       DIR_BIN="$DIR_SOURCE/bin"
  10936.       DIR_PKGS="$DIR_SOURCE/install"
  10937.       return 0
  10938.     elif [ -d $prefix/col/lib ]; then
  10939.       Debug "found Caldera OpenLinux 1.2"
  10940.       CONF_INSTALL_PATH_SRC="col"
  10941.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  10942.       DIR_DATA="$DIR_SOURCE/data"
  10943.       DIR_BIN="$DIR_SOURCE/bin"
  10944.       DIR_PKGS="$DIR_SOURCE/install"
  10945.       return 0
  10946.     elif [ -f $prefix/col/$suffix ]; then
  10947.       Debug "found Caldera OpenLinux 1.1"
  10948.       INSTALL_MODE=LST
  10949.       CONF_INSTALL_PATH_SRC="col"
  10950.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  10951.       DIR_DATA="$DIR_SOURCE/data"
  10952.       DIR_BIN="$DIR_SOURCE/bin"
  10953.       DIR_PKGS="$DIR_SOURCE/install"
  10954.       return 0
  10955.     elif [ -f $prefix/col_10/$suffix ]; then
  10956.       Debug "found Caldera OpenLinux 1.0"
  10957.       CONF_INSTALL_PATH_SRC="col_10"
  10958.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  10959.       DIR_DATA="$DIR_SOURCE/data"
  10960.       DIR_BIN="$DIR_SOURCE/bin"
  10961.       DIR_PKGS="$DIR_SOURCE/install"
  10962.       return 0
  10963.     elif [ -f $prefix/col_10b/$suffix ]; then
  10964.       Debug "found Caldera OpenLinux 1.0 Beta Preview"
  10965.       CONF_INSTALL_PATH_SRC="col_10b"
  10966.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  10967.       DIR_DATA="$DIR_SOURCE/data"
  10968.       DIR_BIN="$DIR_SOURCE/bin"
  10969.       DIR_PKGS="$DIR_SOURCE/install"
  10970.       return 0
  10971.     elif [ -f $prefix/lst_22/$suffix ]; then
  10972.       Debug "found LST 2.2 Power Linux"
  10973.       CONF_INSTALL_PATH_SRC="lst_22"
  10974.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  10975.       DIR_DATA="$DIR_SOURCE/data"
  10976.       DIR_BIN="$DIR_SOURCE/bin"
  10977.       DIR_PKGS="$DIR_SOURCE/install"
  10978.       return 0
  10979.     elif [ -f $prefix/lst_22b/$suffix ]; then
  10980.       Debug "found LST 2.2 Beta Preview"
  10981.       CONF_INSTALL_PATH_SRC="lst_22b"
  10982.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  10983.       DIR_DATA="$DIR_SOURCE/data"
  10984.       DIR_PKGS=$DIR_SOURCE
  10985.       return 0
  10986.     elif [ -f $prefix/lst_21/$suffix ]; then
  10987.       Debug "found LST 2.1 Power Linux"
  10988.       CONF_INSTALL_PATH_SRC="lst_21"
  10989.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  10990.       DIR_DATA="$DIR_SOURCE"
  10991.       DIR_PKGS=$DIR_SOURCE
  10992.       return 0
  10993.     elif [ -f $prefix/Packages/RPMS/calderize-1.0-1.i386.rpm ]; then
  10994.       Debug "found Caldera Network Desktop 1.0"
  10995.       CONF_INSTALL_PATH_SRC="Packages"
  10996.       DIR_SOURCE="$prefix/$CONF_INSTALL_PATH_SRC"
  10997.       DIR_PKGS=$DIR_SOURCE
  10998.       export CND10_MODE=true
  10999.       Msg ":INFO_CND10_WILL_REQUIRE_MODULES_FLOPPY:"
  11000.       MountModulesFloppy
  11001.       return 0
  11002.     else
  11003.       Debug "no known Distribution found under <$prefix>"
  11004.       Error "<$prefix> ; :ERR_INVALID_SOURCE_PATH:"
  11005.       Ask_String DIR_SOURCE "$prefix" || return 1
  11006.       prefix="$ANSWER"
  11007.     fi
  11008.   done
  11009. }
  11010.  
  11011. Do_Calc_Freespace()
  11012. {
  11013.     local i=
  11014.     local PathRegexProof
  11015.     local master_mntpoint
  11016.     local sub_mntpoints
  11017.  
  11018.     FREESPACE=0
  11019.     rm -f $FILE_TMP_VAL
  11020.  
  11021.     if [ $# -eq 0 ]; then
  11022.         PathRegexProof="\/"
  11023.     else
  11024.         PathRegexProof="`echo "$1" | sed 's/\//\\\\\//'`"
  11025.     fi
  11026.  
  11027.     Debug "PathRegexProof=<$PathRegexProof>"
  11028.  
  11029.     # get list of mountpoints for the specified path
  11030.     master_mntpoint="`mount | sed -n '/on '${PathRegexProof}' /p' | cut -d' ' -f 3`"
  11031.     Debug "master_mntpoint=<$master_mntpoint>"
  11032.     if [ -n "$master_mntpoint" ]; then
  11033.         df $master_mntpoint | fgrep '%' | cut -c 37-45 > $FILE_TMP_VAL
  11034.     else
  11035.         # specified path is not a directory. use simple df on its fs
  11036.         df $1 | fgrep '%' | cut -c 37-45 > $FILE_TMP_VAL
  11037.     fi
  11038.  
  11039.     sub_mntpoints="`mount | sed -n '/on '${PathRegexProof}'\//p' | cut -d' ' -f 3`"
  11040.     Debug "sub_mntpoints=<$sub_mntpoints>"
  11041.     if [ -n "$sub_mntpoints" ]; then
  11042.         for i in $sub_mntpoints ; do
  11043.             df $i | fgrep '%' | cut -c 37-45 >> $FILE_TMP_VAL
  11044.         done
  11045.     fi
  11046.  
  11047.     touch $FILE_TMP_VAL
  11048.     for i in `cat $FILE_TMP_VAL` ; do
  11049.         FREESPACE="`do_calc $FREESPACE + $i`"
  11050.     done
  11051.     FREESPACE="`do_calc $FREESPACE \* 1024`"
  11052.     if [ -z "$FREESPACE" ]; then
  11053.         FREESPACE=0
  11054.     fi
  11055.     Debug "summarized FREESPACE=<$FREESPACE>"
  11056.  
  11057.     export FREESPACE
  11058.     return 0
  11059. }
  11060.  
  11061. # calculate space requirements for a given list of packages
  11062. Do_Calc_Needspace()
  11063. {
  11064.   export NEEDSPACE=0
  11065.   local sellist=$1
  11066.  
  11067.   NEEDSPACE="`build_menu -t $sellist -d $FILE_PKGS_DATA -S | cut -d':' -f 7`"
  11068.   NEEDSPACE="`do_calc $NEEDSPACE \* 1024`"
  11069.   Debug "NEEDSPACE => <$NEEDSPACE>" 
  11070. }
  11071.  
  11072. Do_Find_File_To_Pkg()
  11073. {
  11074.   local f_name=Do_Find_File_To_Pkg
  11075.   local f_args=1 # (pkg) -> PKG_FILE
  11076.   local tmpfile=/tmp/pkginfo.$$
  11077.   local pkg="$1"
  11078.   local vers
  11079.   local subdir
  11080.   local pkgpath="$DIR_PKGS/RPMS"
  11081.   export PKG_FILE=unknown
  11082.  
  11083.   Check_Args $f_name $f_args $# "$@" || return 255
  11084.  
  11085.   # get version from pkgs.db
  11086.   db_printf -n -m ":1:$pkg:" -p ":-8:" -f $FILE_PKGS_DATA | sed 's/[     ]*//g' > $tmpfile
  11087.   if [ -s $tmpfile ]; then
  11088.     read vers < $tmpfile
  11089.   fi
  11090.   rm -f $tmpfile
  11091.  
  11092.   Debug "Do_Find_File_To_Pkg $1 -> $pkgpath/$pkg-$vers.${RPMBINEXT}.rpm"
  11093.   if [ -f $pkgpath/$pkg-$vers.${RPMBINEXT}.rpm ]; then
  11094.     # first we look for rpm files
  11095.     PKG_FILE="$pkgpath/$pkg-$vers.${RPMBINEXT}.rpm"
  11096.     Debug "found PKG_FILE=$PKG_FILE (rpm case)"
  11097.     return 0
  11098.   else
  11099.     # support harddisk installs from msdos partitions
  11100.     # get subdir from pkgs.db
  11101.     db_printf -n -m ":1:$pkg:" -p ":-6:" -f $FILE_PKGS_DATA | sed 's/[     ]*//g' > $tmpfile
  11102.     if [ -s $tmpfile ]; then
  11103.       read subdir < $tmpfile
  11104.     fi
  11105.     rm -f $tmpfile
  11106.     Debug "Trying trans.tbl lookup for $pkgpath/$pkg-$vers.${RPMBINEXT}.rpm"
  11107.     Do_Lookup_Trans_Tbl $pkgpath/$pkg-$vers.${RPMBINEXT}.rpm
  11108.     if [ $? -eq 0 ]; then
  11109.       PKG_FILE="$ANSWER"
  11110.     else
  11111.       if [ -d $DIR_PKGS/$subdir ]; then
  11112.         pkgpath=$DIR_PKGS/$subdir
  11113.       fi
  11114.       Debug "Trying trans.tbl lookup for $pkgpath/$pkg-$vers.${RPMBINEXT}.rpm"
  11115.       Do_Lookup_Trans_Tbl $pkgpath/$pkg-$vers.${RPMBINEXT}.rpm
  11116.       if [ $? -eq 0 ]; then
  11117.         PKG_FILE="$ANSWER"
  11118.       else
  11119.         Error "$pkgpath/$pkg-$vers.${RPMBINEXT}.rpm ; :ERR_FILE_NOT_FOUND:"
  11120.         echo "$pkgpath/$pkg-$vers.${RPMBINEXT}.rpm not found" >> /root/tmp/LST/install_error
  11121.         Ask_Bool ABORT_INSTALL y
  11122.         if [ "$ANSWER" = "0" ]; then
  11123.       Do_Reboot
  11124.         fi
  11125.         Is_Expert
  11126.         if [ $? -eq 0 ]; then
  11127.           echo "Enter Path"
  11128.           read PKG_FILE
  11129.           export PKG_FILE
  11130.         fi
  11131.       fi
  11132.     fi
  11133.     return 1
  11134.   fi
  11135. }
  11136.  
  11137. Do_Find_Pkg_To_File()
  11138. {
  11139.     local f_name=Do_Find_Pkg_To_File
  11140.     local f_args=1 # (file) -> PKG_NAME
  11141.     local file="$1"
  11142.  
  11143.     Get_Pkg_Type $file || return 1
  11144.     case $PKG_TYPE in
  11145.     rpm)
  11146.         # rpm package
  11147.         if [ "$CND10_MODE" = "true" ]; then
  11148.             # old rpmextr version
  11149.             rpmextr --shell $file | fgrep PKG_NAME > $FILE_TMP_VAL
  11150.             . $FILE_TMP_VAL
  11151.         else
  11152.             # new rpmextr version
  11153.             PKG_NAME="`rpmextr --tag=name $file`"
  11154.         fi
  11155.         ;;
  11156.     esac
  11157.     export PKG_NAME
  11158.     Debug "Do_Find_Pkg_To_File $1 -> $PKG_NAME"
  11159.     return 0
  11160. }
  11161.  
  11162. # FIXME: this is a really bad hack. We need dependencies...
  11163. Do_Sort_Pkgs()
  11164. {
  11165.     local i
  11166.     local first_pkgs="DEV MAKEDEV dev grep sed ld.so glibc libc aout-libs bash lisa fileutils sh-utils textutils util-linux make kde2compat"
  11167.  
  11168.     # resort pkglist to make sure essential packages are installed first
  11169.     Debug "resorting selected packages"
  11170.     rm -f $FILE_PKGS_SEL.tmp
  11171.     touch $FILE_PKGS_SEL
  11172.     touch $FILE_PKGS_SEL.tmp
  11173.     for i in $first_pkgs `cat $FILE_PKGS_SEL` ; do
  11174.         fgrep -x $i $FILE_PKGS_SEL > /dev/null
  11175.         if [ $? -eq 0 ]; then
  11176.             fgrep -x $i $FILE_PKGS_SEL.tmp > /dev/null
  11177.             if [ $? -ne 0 ]; then
  11178.                 echo "$i" >> $FILE_PKGS_SEL.tmp
  11179.             fi
  11180.         fi
  11181.     done
  11182.     mv $FILE_PKGS_SEL.tmp $FILE_PKGS_SEL
  11183. }
  11184.  
  11185.  
  11186. Do_Sort_Series()
  11187. {
  11188.     local i
  11189.  
  11190.     # resort serieslist to make sure basis and xbasis are installed first
  11191.     mv $FILE_SERIES_SEL $FILE_SERIES_SEL.tmp
  11192.     touch $FILE_SERIES_SEL
  11193.     for i in $LST_SERIES ; do
  11194.         fgrep $i $FILE_SERIES_SEL.tmp > /dev/null
  11195.         if [ $? -eq 0 ]; then
  11196.             echo "$i" >> $FILE_SERIES_SEL
  11197.         fi
  11198.     done
  11199.     rm -f $FILE_SERIES_SEL.tmp
  11200. }
  11201.  
  11202. Do_Transfer_Minimum()
  11203. {
  11204.     local i
  11205.  
  11206.     mkdir -p $DIR_TARGET/bin
  11207.     cp -a /bin/cat /bin/mkdir /bin/basename $DIR_TARGET/bin
  11208.  
  11209.     mkdir -p $DIR_TARGET/lib
  11210.     cp -a /lib/libc.so.4.5.24 $DIR_TARGET/lib
  11211.     ln -sf libc.so.4.5.24 $DIR_TARGET/lib/libc.so.4
  11212.  
  11213.     mkdir -p $DIR_TARGET/etc/rc.d
  11214.     for i in rc0.d rc1.d rc2.d rc3.d rc4.d rc5.d rc6.d ; do
  11215.         mkdir -p $DIR_TARGET/etc/rc.d/$i
  11216.     done
  11217. }
  11218.  
  11219.  
  11220. Do_PHI_Complete_Pkgs()
  11221. {
  11222.     local dep_matrix=$DIR_LIVE/lizard/share/apps/lizard/packages
  11223.     local my_sort="sort"
  11224.     local my_uniq="uniq"
  11225.     local i
  11226.  
  11227.     if [ ! -r $dep_matrix ]; then
  11228.         Debug "Did not find a dependecy matrix under $dep_matrix. Skip."
  11229.         return 1
  11230.     else
  11231.         Debug "PHI completing pkgs with precalculated dependency matrix"
  11232.     fi
  11233.     # try to survive if we don't have sort or unique available
  11234.     sort --version > /dev/null 2>&1 || my_sort='cat -'
  11235.     uniq --version > /dev/null 2>&1 || my_uniq='cat -'
  11236.     touch $FILE_PKGS_SEL
  11237.     for i in `cat $FILE_PKGS_SEL` ; do
  11238.         echo "$i"
  11239.         sed -n "/^${i}:/p" $dep_matrix | \
  11240.             cut -d':' -f 4 | \
  11241.             sed '{
  11242.                 s/,/ /g
  11243.                 s/ /\
  11244. /g
  11245.                 }'
  11246.     done | $my_sort | $my_uniq > $FILE_PKGS_SEL.tmp
  11247.     mv $FILE_PKGS_SEL.tmp $FILE_PKGS_SEL
  11248.     return 0
  11249. }
  11250.  
  11251.  
  11252. Do_Pkg_Install()
  11253. {
  11254.     local myseries=
  11255.     local mydisk=
  11256.     local pkgname=
  11257.     local pkgfile=
  11258.     local i
  11259.  
  11260.     Debug "Do_Pkg_Install <$@>"
  11261.     Has_Source || return 1
  11262.     Has_Target_Path || return 1
  11263.     Has_Selections || return 1
  11264.  
  11265.     prep_use INSTALL || return 1
  11266.     prep_use RPM_INSTALL || return 1
  11267.  
  11268.     Info ":INFO_WAIT:"
  11269.     Do_Sort_Pkgs
  11270.     Do_Sort_Series
  11271.     build_menu -t $FILE_PKGS_SEL -d $FILE_PKGS_DATA -n -p ":5:" > $FILE_DISKS_SEL
  11272.   
  11273.     if [ "`get_val -f /etc/lst.cnf CONF_COL_EDITION`" != "SBA" ]; then
  11274.         Msg2 PKG_INSTALL || continue
  11275.     fi
  11276.  
  11277.     Info ":INFO_WAIT:"
  11278.  
  11279.     # After this point there is no way to stop the installation
  11280.     # and to step back so we can safely delete and move some things
  11281.     # to avoid running out of ramdisk space
  11282.     
  11283.     # Copy minimal files from ramdisk to root
  11284.     Do_Transfer_Minimum
  11285.  
  11286.     # Delete the unused modules from the ramdisk
  11287.     Delete_unused_modules
  11288.  
  11289.     # switch the log area
  11290.     Do_Switch_Log_Area
  11291.  
  11292.     # mount /proc additionally under $DIR_TARGET to make sure
  11293.     # the /dev/core symlink points to something usefull
  11294.     mkdir -p $DIR_TARGET/proc
  11295.     mount -t proc /proc $DIR_TARGET/proc
  11296.     
  11297.     export DIR_LOG_PKGS=$DIR_TARGET/install
  11298.     export DIR_LOG_INSTALLED=$DIR_LOG_PKGS/installed
  11299.     export DIR_LOG_CATALOG=$DIR_LOG_PKGS/catalog
  11300.     export DIR_LOG_CONTENTS=$DIR_LOG_PKGS/contents
  11301.     export DIR_LOG_CONFLICTS=$DIR_LOG_PKGS/conflicts
  11302.     export DIR_LOG_SCRIPTS=$DIR_LOG_PKGS/scripts
  11303.     export DIR_LOG_DISKS=$DIR_LOG_PKGS/disks
  11304.     export DIR_LOG_SAVED=$DIR_LOG_PKGS/saved
  11305.     export DIR_LOG_REPLACED=$DIR_LOG_PKGS/replaced
  11306.     export DIR_LOG_DELETED=$DIR_LOG_PKGS/deleted
  11307.     export DIR_LOG_ERRORS=$DIR_LOG_PKGS/errors
  11308.     for logdir in $DIR_LOG_ANALYSE $DIR_LOG_LOG $DIR_LOG_INSTALLED $DIR_LOG_SCRIPTS $DIR_LOG_DISKS $DIR_LOG_CATALOG $DIR_LOG_CONTENTS $DIR_LOG_CONFLICTS $DIR_LOG_SAVED $DIR_LOG_REPLACED $DIR_LOG_DELETED $DIR_LOG_ERRORS ; do
  11309.         mkdir -p $logdir
  11310.     done
  11311.  
  11312.     Get_Install_Stat
  11313.  
  11314.     # first look for base directory (COL, LST 2.2, CND 1.0, RedHat 3.0.3)
  11315.     if [ -f $DIR_DATA/framework.cgz ]; then
  11316.         Debug "file $DIR_DATA/framework.cgz found"
  11317.         Debug "using cpio install mode"
  11318.         Debug "Installing framework.cgz"
  11319.         Do_Uncpio $DIR_DATA/framework.cgz || return 1
  11320.         for i in $DIR_TARGET/opt/{bin,man} ; do
  11321.             if [ ! -d $DIR_TARGET/$i ]; then
  11322.                 mkdir -p $DIR_TARGET/$i
  11323.             fi
  11324.         done
  11325.         for i in passwd shadow group hosts sysconfig/network; do
  11326.             if [ ! -r $DIR_TARGET/etc/$i -a -r $DIR_TARGET/etc/${i}- ]; then
  11327.                 mv $DIR_TARGET/etc/${i}- $DIR_TARGET/etc/$i
  11328.             fi
  11329.         done
  11330.         rm -vf $DIR_TARGET/etc/*- $DIR_TARGET/etc/sysconfig/*-
  11331.     fi
  11332.  
  11333.     # prefer install driven by pkgs.sel (COL 1.0, CND 1.0, RedHat 3.0.3)
  11334.     if [ -d $DIR_PKGS/RPMS ]; then
  11335.         Debug "file $DIR_PKGS/RPMS found"
  11336.         Debug "using RPMS install mode"
  11337.         for pkgname in `cat $FILE_PKGS_SEL` ; do
  11338.             Do_Find_File_To_Pkg $pkgname
  11339.             pkgfile="$PKG_FILE"
  11340.             Debug "Install $pkgname ($pkgfile)" 
  11341.             Do_Raw_rpm_Install $pkgfile $pkgname
  11342.         done
  11343.         if [ "$INSTALL_MODE" = "OpenLinux" ]; then
  11344.             Fix_12_Alpha before_postin
  11345.             Do_All_Postin
  11346.             Fix_12_Alpha after_postin
  11347.         fi
  11348.         return 0
  11349.     # support LST install (COL, LST 2.2, LST 2.2b, LST 2.1)
  11350.     elif [ -f $DIR_PKGS/basis1/basis1.idx ]; then
  11351.         Debug "file $DIR_PKGS/basis1/basis1.idx found"
  11352.         Debug "using COL/LST series install mode"
  11353.         for myseries in `cat $FILE_SERIES_SEL` ; do
  11354.             # FIXME: hardcoded maximum of 16 disks per series
  11355.             for disknum in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ; do
  11356.                 mydisk=$myseries$disknum
  11357.                 fgrep -x $mydisk $FILE_DISKS_SEL > /dev/null
  11358.                 if [ $? -ne 0 ]; then continue ; fi
  11359.                 Debug "installing LST disk $mydisk"
  11360.                 for pkgfile in $DIR_PKGS/$mydisk/*.rpm ; do
  11361.                     if [ ! -f $pkgfile ]; then continue ; fi
  11362.                     Do_Find_Pkg_To_File $pkgfile
  11363.                     pkgname="$PKG_NAME"
  11364.                     fgrep -x $pkgname $FILE_PKGS_SEL > /dev/null
  11365.                     if [ $? -ne 0 ]; then
  11366.                         Debug "$pkgname is not selected. Skipping."
  11367.                         continue
  11368.                     fi
  11369.                     Do_Raw_rpm_Install $pkgfile $pkgname
  11370.                 done
  11371.             done
  11372.         done
  11373.         return 0
  11374.     else
  11375.         Debug "no idea how to install $DIR_PKGS"
  11376.         return 1
  11377.     fi
  11378.     return 0
  11379. }
  11380.  
  11381. Check_Pkg_Installed()
  11382. {
  11383.     local p="$1"
  11384.  
  11385.     # check for rpm package
  11386.     rpm -qi $p > /dev/null 2> /dev/null
  11387.     if [ $? -eq 0 ]; then    
  11388.         ANSWER=rpm
  11389.         return 0
  11390.     fi
  11391.     return 1
  11392. }
  11393.  
  11394. Do_Pkg_Remove_RPM()
  11395. {
  11396.   local retval
  11397.   local p="$1"
  11398.  
  11399.   rpm --nodeps -e $p 2> $FILE_TMP_ERR
  11400.   retval=$?
  11401.   if [ $retval -eq 0 ]; then
  11402.     echo "`date` removal of pkg $p was ok ($retval)" >> $DIR_TARGET/var/adm/LST/log/remove.success
  11403.     return 0
  11404.   else
  11405.     echo "`date` removal of pkg $p failed ($retval)" >> $DIR_TARGET/var/adm/LST/log/remove.failed
  11406.     Error --file $FILE_TMP_ERR "rpm removal of $p failed"
  11407.     return 1
  11408.   fi
  11409. }
  11410.  
  11411. Do_Pkg_Remove_TGZ()
  11412. {
  11413.   local p="$1"
  11414.  
  11415.   if [ -f $DIR_LOG_INSTALLED/$p ]; then
  11416.     ( cd $DIR_TARGET; rm -f `cat $DIR_LOG_INSTALLED/${p}` ) 
  11417.   fi
  11418. }
  11419.  
  11420. Do_Pkg_Remove_META()
  11421. {
  11422.   local p="$1"
  11423.  
  11424.   for s in doinst.sh dobefore.sh doafter.sh ; do
  11425.     if [ -f $DIR_LOG_SCRIPTS/${p}.${s} ]; then
  11426.       History_Install "removing $ptype package $p (${p}.${s}) ..."
  11427.       rm -f $DIR_LOG_SCRIPTS/${p}.${s}
  11428.     fi
  11429.   done
  11430.   History_Install "removing $ptype package $p ($DIR_LOG_INSTALLED/${p}) ..."
  11431.   rm -f $DIR_LOG_INSTALLED/${p}
  11432. }
  11433.  
  11434. # deinstallation of a package by means of a contents file
  11435. #
  11436. Do_Pkg_Remove()
  11437. {
  11438.   local f_name=Do_Pkg_Remove
  11439.   local f_args=1 # (pkg_name) ->
  11440.   local s
  11441.   local p
  11442.   local ptype
  11443.  
  11444.   Check_Args $f_name $f_args $# "$@" || return 255
  11445.  
  11446.   p="$1"
  11447.  
  11448.   Check_Pkg_Installed $p
  11449.   if [ $? -ne 0 ]; then
  11450.     Error "${p} ; :ERR_PKG_NOT_INSTALLED:"
  11451.     return 1
  11452.   fi
  11453.   ptype="$ANSWER"
  11454.  
  11455.   History_Install "removing $ptype package $p (files) ..."
  11456.   case $ptype in
  11457.   rpm)
  11458.     Do_Pkg_Remove_RPM $p
  11459.     ;;
  11460.   esac
  11461.   Do_Pkg_Remove_META $p
  11462.   History_Install "removing $ptype package $p (done)"
  11463. }
  11464.  
  11465. Do_Uncpio()
  11466. {
  11467.     local retval=
  11468.  
  11469.     mkdir -p $DIR_TARGET/tmp/LST
  11470.     echo "#!/bin/sh" > /tmp/LST/do_uncpio
  11471.     echo "cd $DIR_TARGET || exit 42" >> /tmp/LST/do_uncpio
  11472.     echo 'cat $1 | gzip -d | cpio -ivumd && exit 0' >> /tmp/LST/do_uncpio
  11473.     chmod 755 /tmp/LST/do_uncpio
  11474.  
  11475.     sync
  11476.     /tmp/LST/do_uncpio $1 2> $DIR_LOG_INSTALLED/`basename $1 .cgz` && return 0
  11477.     History_Install "do_uncpio $1 exited with error code <$?> (bad package ?)"
  11478.     Debug_Stop
  11479.     return 1
  11480. }
  11481.  
  11482. Do_4_Digit()
  11483. {
  11484.   local was="$1"
  11485.   local now=
  11486.  
  11487.   was="`echo $was | sed 's/^[0]*//'`" 
  11488.  
  11489.   if [ $was -gt 999 ]; then
  11490.     now="$was"
  11491.   elif [ $was -gt 99 ]; then
  11492.     now="0$was"
  11493.   elif [ $was -gt 9 ]; then
  11494.     now="00$was"
  11495.   else
  11496.     now="000$was"
  11497.   fi
  11498.   echo "$now"
  11499.   return 0
  11500. }
  11501.  
  11502. Do_Unrpm()
  11503. {
  11504.   local retval=
  11505.   local num=
  11506.   local num4digit=
  11507.  
  11508.   mkdir -p $DIR_TARGET/tmp/LST
  11509.   echo "#!/bin/sh" > /tmp/LST/do_unrpm
  11510.   if [ "$DIR_TARGET" = '/' ]; then
  11511.     echo "rpm -i --nodeps $1 2> $FILE_TMP_ERR && exit 0" >> /tmp/LST/do_unrpm
  11512.   else
  11513.     if [ "$INSTALL_MODE" = "OpenLinux" ]; then
  11514.       if [ -f /source/data/use-force ]; then
  11515.         echo "rpm -i --force --nodeps --noscripts --root $DIR_TARGET $1 2> $FILE_TMP_ERR && exit 0" >> /tmp/LST/do_unrpm
  11516.       else
  11517.         echo "rpm -i --nodeps --noscripts --root $DIR_TARGET $1 2> $FILE_TMP_ERR && exit 0" >> /tmp/LST/do_unrpm
  11518.       fi
  11519.     else
  11520.       if [ "$CND10_MODE" = "true" ]; then
  11521.         echo "cd $DIR_TARGET || exit 1" >> /tmp/LST/do_unrpm
  11522.         echo "rpmq -i $1 2> $FILE_TMP_ERR && exit 0" >> /tmp/LST/do_unrpm
  11523.       else
  11524.         echo "rpm -i --force --root $DIR_TARGET $1 2> $FILE_TMP_ERR && exit 0" >> /tmp/LST/do_unrpm
  11525.       fi
  11526.     fi
  11527.   fi
  11528.   echo "exit 1" >> /tmp/LST/do_unrpm
  11529.  
  11530.   chmod 755 /tmp/LST/do_unrpm
  11531.   # If we run from the lisa live filesystem then use tty4 for progress echo
  11532.   if [ -n "`sed -n '/^er=/p' /tmp/cmdline | fgrep text`" ]; then
  11533.     cat /tmp/LST/do_unrpm > /dev/tty4
  11534.   else
  11535.     cat /tmp/LST/do_unrpm > /dev/tty7
  11536.   fi
  11537.  
  11538.   sync
  11539.   /tmp/LST/do_unrpm $1 2> $DIR_LOG_ERRORS/$PKG_NAME
  11540.   retval=$?
  11541.   # remove empty error logs
  11542.   if [ ! -s $DIR_LOG_ERRORS/$PKG_NAME ]; then
  11543.     rm -f $DIR_LOG_ERRORS/$PKG_NAME
  11544.   fi
  11545.   if [ $retval -ne 0 ]; then
  11546.     History_Install "do_unrpm $1 exited with error code <$retval> (bad package ?)"
  11547.     # Debug_Stop
  11548.     Error --file $FILE_TMP_ERR "rpm install of $1 failed"
  11549.     return $retval
  11550.   else
  11551.     rm -f $FILE_TMP_ERR
  11552.   fi
  11553.  
  11554.   # extract post install script
  11555.   rpmextr --post $1 > $DIR_TARGET/install/doinst.sh
  11556.   if [ ! -s $DIR_TARGET/install/doinst.sh ]; then
  11557.     rm -f $DIR_TARGET/install/doinst.sh
  11558.   else
  11559.     chmod 755 $DIR_TARGET/install/doinst.sh
  11560.     cp -a $DIR_TARGET/install/doinst.sh $DIR_TARGET/install/scripts/$PKG_NAME.postin
  11561.     if [ "$DIR_TARGET" != '/' ]; then
  11562.       if [ "$INSTALL_MODE" = "OpenLinux" ]; then
  11563.         mkdir -p $DIR_TARGET/install/postin
  11564.         num="`do_calc $PKG_NUM_DONE + 1 `"
  11565.         num4digit="`Do_4_Digit $num`"
  11566.         cp -a $DIR_TARGET/install/doinst.sh $DIR_TARGET/install/postin/${num4digit}.${PKG_NAME}
  11567.       fi
  11568.     fi
  11569.   fi
  11570.   if [ "$CND10_MODE" != "true" ]; then
  11571.     rm -f $DIR_TARGET/install/doinst.sh
  11572.     # extract short and long listings
  11573.     rpm -ql $PKG_NAME > $DIR_TARGET/install/installed/$PKG_NAME
  11574.     rpm -qlv $PKG_NAME > $DIR_TARGET/install/contents/$PKG_NAME
  11575.   fi
  11576.   return 0
  11577. }
  11578.  
  11579. Do_Untar()
  11580. {
  11581.   local contents=$DIR_TARGET/tmp/LST/C
  11582.   local files=$DIR_TARGET/tmp/LST/F
  11583.   local retval=
  11584.   local failure=
  11585.  
  11586.   mkdir -p $DIR_TARGET/tmp/LST
  11587.   echo "#!/bin/sh" > /tmp/LST/do_untar
  11588.   echo "cd $DIR_TARGET || exit 1" >> /tmp/LST/do_untar
  11589.   echo 'tar -zxvvlpf $1 $2 && exit 0' >> /tmp/LST/do_untar
  11590.   chmod 755 /tmp/LST/do_untar
  11591.  
  11592.   while [ 1 ]; do
  11593.     rm -f $contents $files
  11594.     sync
  11595.     /tmp/LST/do_untar $1 $2 > $contents 2> $FILE_TMP_ERR
  11596.     retval=$?
  11597.     if [ $retval -ne 0 ]; then
  11598.       if [ -z "$failure" ]; then
  11599.     History_Install "tar $@ exited with error code <$retval> (bad package ?)"
  11600.     History_Install "retrying tar $@ ..."
  11601.     failure=true
  11602.       else
  11603.     Error "$PKG_NAME ; :ERR_BAD_PKG:" || return 1
  11604.     failure=
  11605.       fi
  11606.     else
  11607.       if [ -n "$failure" ]; then
  11608.     History_Install "retry of tar $@ completed successfully."
  11609.       fi
  11610.       cp -a $contents $DIR_LOG_CONTENTS/$PKG_NAME
  11611.       sed -e '/\/$/d' -e 's/.* //' $contents | cut -d' ' -f 8 > $DIR_LOG_INSTALLED/$PKG_NAME
  11612.       return 0
  11613.     fi
  11614.   done
  11615. }
  11616.  
  11617. Do_Save_Conflicts()
  11618. {
  11619.     local contents=$DIR_TARGET/tmp/LST/C
  11620.     local files=$DIR_TARGET/tmp/LST/F
  11621.  
  11622.     Debug "checking for conflicts"
  11623.     for dummy in `cat $files`; do
  11624.         if [ -f $DIR_TARGET/$dummy ]; then
  11625.             Do_Log -f $DIR_LOG_CONFLICTS/$PKG_NAME "$dummy"
  11626.             if [ "$PKG_SAVE" = "true" ]; then
  11627.                 Do_Log -f $DIR_LOG_SAVED/$PKG_NAME "$dummy.before.$CONF_LST_VERSION"
  11628.                 History_Install "$dummy saved as $dummy.before.$CONF_LST_VERSION"
  11629.                 ln -f $DIR_TARGET/$dummy $DIR_TARGET/$dummy.before.$CONF_LST_VERSION
  11630.             fi
  11631.             rm -f $DIR_TARGET/$dummy
  11632.             Do_Log -f $DIR_LOG_REPLACED/$PKG_NAME "$dummy"
  11633.             History_Install "$dummy will be replaced"
  11634.         fi
  11635.     done
  11636. }
  11637.  
  11638. Fix_col22()
  11639. {
  11640.     # remove postin scripts that currently hang
  11641.     rm -f $DIR_TARGET/install/postin/*.kpilot
  11642.     mkdir -p $DIR_TARGET/var/run
  11643.     mkdir -p $DIR_TARGET/var/lock
  11644.     mkdir -p $DIR_TARGET/var/log
  11645. }
  11646.  
  11647. # FIXME12: this whole function should disappear
  11648. Fix_12_Alpha()
  11649. {
  11650.     local uname_r
  11651.     local uname_v
  11652.  
  11653.     if [ "$1" = "target_mounted" ]; then
  11654.         # create linux symlink if not there
  11655.         mkdir -p $DIR_TARGET/usr/src
  11656.         if [ ! -L $DIR_TARGET/usr/src/linux ]; then
  11657.             ln -s linux-"`uname -r`" $DIR_TARGET/usr/src/linux
  11658.         fi
  11659.     elif [ "$1" = "before_postin" ]; then
  11660.         if [ -f /source/data/use-mini-lisa ]; then
  11661.             # use mini-lisa because new one is under construction
  11662.             cp -a $DIR_TARGET/bin/lisa $DIR_TARGET/bin/lisa.big
  11663.             cp -a $DIR_BIN/mini-lisa $DIR_TARGET/bin/lisa
  11664.         fi
  11665.         Fix_ldconfig
  11666.         Fix_col22
  11667.     elif [ "$1" = "after_postin" ]; then
  11668.         if [ -f /source/data/use-mini-lisa ]; then
  11669.             # install new lisa
  11670.             mv $DIR_TARGET/bin/lisa $DIR_TARGET/bin/mini-lisa
  11671.             mv $DIR_TARGET/bin/lisa.big $DIR_TARGET/bin/lisa
  11672.         fi
  11673.  
  11674.         # override old lisa-2.4.0 that was still in lisa-3.0-1 RPM
  11675.         if [ "`get_val -f $DIR_TARGET/bin/lisa SCRIPT_VERSION`" = "2.4.0" ]; then
  11676.             cp -a /bin/lisa $DIR_TARGET/bin/lisa
  11677.         fi
  11678.  
  11679.         # try to adjust the modules load files again
  11680.         uname_r="`Get_uname_r`"
  11681.         uname_v="`Get_uname_v`"
  11682.         # create modules load files again if kernels differ
  11683.         if [ "$uname_v" != "`uname -v`" ]; then
  11684.             if [ -f $DIR_TARGET/etc/modules/`uname -r`/"`uname -v`".default ]; then
  11685.                 mkdir -p $DIR_TARGET/etc/modules/${uname_r}
  11686.                 cp -a $DIR_TARGET/etc/modules/`uname -r`/"`uname -v`".default $DIR_TARGET/etc/modules/${uname_r}/"${uname_v}".default 
  11687.             fi
  11688.             if [ -f $DIR_TARGET/etc/modules/`uname -r`/"`uname -v`".rootfs ]; then
  11689.                 mkdir -p $DIR_TARGET/etc/modules/${uname_r}
  11690.                 cp -a $DIR_TARGET/etc/modules/`uname -r`/"`uname -v`".rootfs $DIR_TARGET/etc/modules/${uname_r}/"$uname_v".rootfs
  11691.             fi
  11692.             # adjust the initrd again
  11693.             Set_modules_autoload
  11694.             Set_initrd
  11695.         fi
  11696.     fi
  11697. }
  11698.  
  11699. Do_All_Postin()
  11700. {
  11701.     local script
  11702.     local short
  11703.     local postin_retval
  11704.     local pkg
  11705.     local num_done=0
  11706.     local num_all=0
  11707.     local percent=0
  11708.     local label_header="`Do_Translate \":INFO_RPM_INSTALL_TITLE:\"` (postin)"
  11709.  
  11710.     mkdir $DIR_TARGET/install/postin.errors
  11711.     # calc number of postin scripts to execute
  11712.     num_all="`ls -l $DIR_TARGET/install/postin/* | get_info -l`"
  11713.     num_all="`do_calc $num_all - 1`"
  11714.     for script in $DIR_TARGET/install/postin/* ; do
  11715.         short="`basename $script`"
  11716.         if [ -f $script ]; then
  11717.             pkg="`echo $short | cut -c 6- `"
  11718.             # calc percentage done
  11719.             percent="`do_calc 100 \* $num_done`"
  11720.             percent="`do_calc $percent / $num_all`"
  11721.             # this would be the simple solution
  11722.             # Info "Processing postin scripts ($num_done/$num_all) ;  ;  Next script is from $pkg ; ; :INFO_WAIT:"
  11723.             $CMD_BOX --nobutton -P "$percent" --height 8 --width 60 -r --title "$label_header" --info "$pkg ($num_done/$num_all)"
  11724.             Debug "calling $script script"
  11725.             History_Install "calling $script ..." 
  11726.             ( cd $DIR_TARGET; chroot $DIR_TARGET sh -c install/postin/$short ) > $DIR_TARGET/install/postin.errors/$short 2>&1
  11727.             postin_retval=$?
  11728.             if [ $postin_retval -ne 0 ]; then
  11729.                     echo "`date` $DIR_TARGET/install/postin/$short failed ($postin_retval)" >> $DIR_TARGET/var/adm/LST/log/postin.failed
  11730.                     # Error "rpm postin of $short failed"
  11731.             fi
  11732.             # remove empty error logs
  11733.             if [ ! -s $DIR_TARGET/install/postin.errors/$short ]; then
  11734.                 rm -f $DIR_TARGET/install/postin.errors/$short
  11735.             fi
  11736.             num_done="`do_calc $num_done + 1`"
  11737.         fi
  11738.     done
  11739.     echo "`date` ======== initial install done ========" >> $DIR_TARGET/var/adm/LST/log/postin.failed
  11740.     echo "`date` ======== initial install done ========" >> $DIR_TARGET/var/adm/LST/log/install.failed
  11741.     echo "`date` ======== initial install done ========" >> $DIR_TARGET/var/adm/LST/log/install.success
  11742.     return 0
  11743. }
  11744.  
  11745.  
  11746. # raw installation of rpm pkgs
  11747. #
  11748.  
  11749. Do_Raw_rpm_Install()
  11750. {
  11751.   local my_lang="`get_val CONF_LST_LANG`"
  11752.   local dir=`dirname $1`
  11753.   local file=`basename $1`
  11754.   local full=$1
  11755.   local pkg=$2
  11756.   local script=
  11757.   local size=
  11758.   local dummy
  11759.   local rpmextr_info
  11760.   local pkg_info
  11761.   local pkg_size
  11762.   local label_header="`Do_Translate \":INFO_RPM_INSTALL_TITLE:\"`"
  11763.   local label_file="`Do_Translate \":LABEL_FILE:\"`"
  11764.   local label_info="`Do_Translate \":LABEL_INFO:\"`"
  11765.   local label_installed="`Do_Translate \":LABEL_INSTALLED:\"`"
  11766.   local rpm_retval=0
  11767.   local postin_retval=0
  11768.  
  11769.   Debug "processing package $file start"
  11770.   Debug -d "params: <$*>"
  11771.  
  11772.   Get_Pkg_Info $full
  11773.   pkg_size="`do_calc $PKG_SIZE / 1024`"
  11774.  
  11775.   sum_installed="$PKG_NUM_DONE/$PKG_NUM_ALL ($PKG_KB_DONE/$PKG_KB_ALL kB)"
  11776.   if [ "$PKG_KB_DONE" -gt 0 -a "$PKG_KB_ALL" -gt 0 ]; then
  11777.     percent="`do_calc 100 \* $PKG_KB_DONE`"
  11778.     percent="`do_calc $percent / $PKG_KB_ALL`"
  11779.   elif [ "$PKG_NUM_ALL" -gt 0 -a "$PKG_KB_ALL" -gt 0 ]; then
  11780.     percent="`do_calc 100 \* $PKG_NUM_DONE`"
  11781.     percent="`do_calc $percent / $PKG_NUM_ALL`"
  11782.   else
  11783.     percent=0
  11784.     sum_installed="$PKG_NUM_DONE ($PKG_KB_DONE kB)"
  11785.   fi
  11786.   # fix rounding bug if using kB instead of packages
  11787.   if [ "$percent" = "100" ]; then
  11788.       percent=99
  11789.   fi
  11790.  
  11791.   Get_Filesystem_Usage --install > $FILE_TMP_MSG
  11792.  
  11793.   if [ "$my_lang" = "de" ]; then
  11794.     menutitle="Dateisystem Gr÷▀e(kB) frei(kB) benutzt Mountpunkt"
  11795.   else
  11796.     menutitle="Filesystem   size(kB) free(kB)  used  mount point"
  11797.   fi
  11798.  
  11799.   # the rest is to be browsed...
  11800.   sed -e '1d' $FILE_TMP_MSG > $FILE_TMP_VAL
  11801.   Debug -D "FILE_TMP_VAL:"
  11802.   Debug -c cat $FILE_TMP_VAL
  11803.  
  11804.   $CMD_BOX --nobutton -P "$percent" -r --title "$label_header" --menutitle "$menutitle" --text "$label_file $file ($pkg_size kB) ; $label_installed $sum_installed ; ; $label_info $PKG_INFO" --browse $FILE_TMP_VAL
  11805.  
  11806.   History_Install "start installing ..."
  11807.   # FIXME: Do_Save_Conflicts should happen here 
  11808.   Debug "extracting $full"
  11809.   Do_Unrpm $full
  11810.   rpm_retval=$?
  11811.  
  11812.   for script in doinst.sh doafter.sh ; do
  11813.     if [ -f $DIR_TARGET/install/$script ]; then
  11814.       Debug "calling $script script"
  11815.       History_Install "calling $script ..." 
  11816.       if [ "$INSTALL_MODE" != "OpenLinux" ]; then
  11817.         ( cd $DIR_TARGET; chroot $DIR_TARGET sh -c install/$script ) 2>&1 | Debug -p
  11818.         postin_retval=$?
  11819.       fi
  11820.       mv $DIR_TARGET/install/$script $DIR_LOG_SCRIPTS/$PKG_NAME.$script
  11821.     fi
  11822.   done
  11823.   PKG_NUM_DONE=`do_calc $PKG_NUM_DONE + 1 `
  11824.   size="` do_calc $PKG_SIZE / 1024 `"
  11825.   PKG_KB_DONE=`do_calc $PKG_KB_DONE + $size `
  11826.   Debug "processing package $file done"
  11827.  
  11828.   if [ "$rpm_retval" != 0 -o "$postin_retval" != 0 ]; then
  11829.     History_Install "installation of $file failed ($rpm_retval/$postin_retval)"
  11830.     echo "`date` installation of $file failed ($rpm_retval/$postin_retval)" >> $DIR_TARGET/var/adm/LST/log/install.failed
  11831.     return 1
  11832.   else
  11833.     History_Install "installation sucessfully completed"
  11834.     echo "`date` installation of $file was ok ($rpm_retval/$postin_retval)" >> $DIR_TARGET/var/adm/LST/log/install.success
  11835.     return 0
  11836.   fi
  11837. }
  11838.  
  11839. Get_Install_Stat()
  11840. {
  11841.   if [ -s $FILE_PKGS_SEL ]; then
  11842.     export PKG_NUM_ALL="`get_info -lf $FILE_PKGS_SEL`"
  11843.     Debug "PKG_NUM_ALL=<$PKG_NUM_ALL>" 
  11844.   else
  11845.     export PKG_NUM_ALL=0
  11846.   fi
  11847.   if [ -s $FILE_PKGS_SEL -a -s $FILE_PKGS_DATA ]; then
  11848.     if [ -z "$NEEDSPACE" ]; then
  11849.       NEEDSPACE=0
  11850.     fi
  11851.     if [ "$NEEDSPACE" -eq "0" ]; then
  11852.       Info ":INFO_CALCULATING_PKG_SIZES:"
  11853.       build_menu -t $FILE_PKGS_SEL -d $FILE_PKGS_DATA -S | cut -d':' -f 7 > /tmp/val
  11854.     else
  11855.       do_calc $NEEDSPACE / 1024 > /tmp/val
  11856.     fi
  11857.     export PKG_KB_ALL="`cat /tmp/val`"
  11858.     Debug "PKG_KB_ALL=<$PKG_KB_ALL>"
  11859.   else
  11860.     export PKG_KB_ALL=0
  11861.   fi
  11862.   export PKG_NUM_DONE=0
  11863.   export PKG_KB_DONE=0
  11864. }
  11865.  
  11866. Get_Pkg_Info()
  11867. {
  11868.   local f_name=Get_Pkg_Info
  11869.   local f_args=1 # (pkg_name/pkg_file) ->
  11870.   local tmpfile=/tmp/pkginfo.$$
  11871.   local my_lang="`get_val CONF_LST_LANG`"
  11872.   local pkg_dict=$FILE_PKGS_INDEX
  11873.   export PKG_SERVICE="unknown"
  11874.   export PKG_NAME="unknown"
  11875.   export PKG_SEL="unknown"
  11876.   export PKG_PRIO="unknown"
  11877.   export PKG_PRIORITY="unknown"
  11878.   export PKG_SIZE="unknown"
  11879.   export PKG_DISK="unknown"
  11880.   export PKG_USAGE="unknown"
  11881.   export PKG_VERS="unknown"
  11882.   export PKG_RELEASE="unknown"
  11883.   export PKG_GROUP="unknown"
  11884.   export PKG_SERVICE="unknown"
  11885.   export PKG_SERIES="unknown"
  11886.   export PKG_INFO="unknown"
  11887.   export PKG_COPYRIGHT="unknown"
  11888.   export PKG_SRC="unknown"
  11889.   export PKG_VENDOR="unknown"
  11890.   export PKG_DISTRIBUTION="unknown"
  11891.  
  11892.   Check_Args $f_name $f_args $# "$@" || return 255
  11893.  
  11894.   if [ -f /usr/lib/LST/$my_lang/pkgs.idx ]; then
  11895.     pkg_dict=/usr/lib/LST/$my_lang/pkgs.idx
  11896.   fi
  11897.  
  11898.   PKG_FILE="$1"
  11899.   Check_File $PKG_FILE
  11900.   if [ $? -eq 0 ]; then
  11901.     # arg was a file name
  11902.     Do_Find_Pkg_To_File $PKG_FILE || return 1
  11903.   else
  11904.     # arg probably was a pkg name
  11905.     PKG_NAME="$1"
  11906.     Do_Find_File_To_Pkg $PKG_NAME || return 1
  11907.   fi
  11908.  
  11909.   # Get specific pkg info
  11910.   case $PKG_TYPE in
  11911.   rpm)
  11912.     # get data from rpm header
  11913.     rpmextr --shell $PKG_FILE > $tmpfile
  11914.     . $tmpfile
  11915.     rm -f $tmpfile
  11916.     # get data from pkgs.db
  11917.     db_printf -n -m ":1:$PKG_NAME:" -p ":3:4:5:-6:7:" -f $FILE_PKGS_DATA > $tmpfile
  11918.     if [ -s $tmpfile ]; then
  11919.       read PKG_SEL PKG_PRIO PKG_SIZE PKG_DISK PKG_USAGE < $tmpfile
  11920.     fi
  11921.     rm -f $tmpfile
  11922.     ;;
  11923.   esac
  11924.  
  11925.   # get package description (multilingual)
  11926.   PKG_INFO="`Do_Translate \":$PKG_NAME:\" $pkg_dict`"
  11927.   if [ "$PKG_INFO" = ":$PKG_NAME:" ]; then
  11928.     PKG_INFO="`rpmextr --tag=info $file`"
  11929.     if [ -z "$PKG_INFO" ]; then
  11930.       PKG_INFO="unknown"
  11931.     fi
  11932.   fi
  11933.  
  11934.   # selected if it is in the selection list
  11935.   if [ -n "$FILE_PKGS_SEL" ]; then
  11936.     if [ -s $FILE_PKGS_SEL ]; then
  11937.       Check_Found "$PKG_NAME" "$FILE_PKGS_SEL"
  11938.       if [ $? -eq 0 ]; then
  11939.         PKG_SEL=j
  11940.       else
  11941.         PKG_SEL=n
  11942.       fi
  11943.     else
  11944.       PKG_SEL=
  11945.     fi
  11946.   fi
  11947.  
  11948.   # get real pkg usage
  11949.   if [ -z "$PKG_SIZE" ]; then
  11950.     PKG_SIZE="`gzip -l $PKG_FILE | fgrep '%' | cut -c 10-20`"
  11951.   fi
  11952.  
  11953.   # get real file size
  11954.   if [ -n "$PKG_FILE" ]; then
  11955.     PKG_USAGE="`filesize $PKG_FILE`"
  11956.   fi
  11957.  
  11958.   if [ -n "$PKG_PRIO" -a "$PKG_PRIO" != "unknown" ]; then
  11959.     PKG_PRIORITY="`Do_Translate \":TYPE_PRIO_$PKG_PRIO:\"`"
  11960.     if [ "$PKG_PRIORITY" = ":TYPE_PRIO_$PKG_PRIO:" ]; then
  11961.       PKG_PRIORITY="unknown"
  11962.     fi
  11963.   fi
  11964.  
  11965.   if [ -n "$PKG_DISK" -a "$PKG_DISK" != "unknown" ]; then
  11966.     PKG_SERIES="`echo $PKG_DISK | sed 's/[0-9]*$//'`"
  11967.   fi
  11968. }
  11969.  
  11970. # Get_Pkg_Type FILE
  11971. #
  11972. Get_Pkg_Type()
  11973. {
  11974.   local f_name=Get_Pkg_Type
  11975.   local f_args=1 # (file) -> PKG_TYPE, PKGEXT
  11976.   local pkgtype
  11977.   local pkgext
  11978.   export PKG_TYPE=unknown
  11979.   export PKGEXT=unknown
  11980.  
  11981.   Check_Args $f_name $f_args $# "$@" || return 255
  11982.  
  11983.   for pkgtype in rpm ; do
  11984.     case $pkgtype in
  11985.     rpm)
  11986.       if [ "`basename $1 .$pkgtype`" != "`basename $1`" ]; then
  11987.         PKGEXT="$pkgtype"
  11988.         PKG_TYPE="$pkgtype"
  11989.         return 0
  11990.       fi
  11991.       ;;
  11992.     esac
  11993.   done
  11994. # FIXME: fallback for trans.tbl mode -> assume rpm
  11995.   PKGEXT="rpm"
  11996.   PKG_TYPE="rpm"
  11997.   return 0
  11998.   Error "$1 ; :ERR_UNKNOWN_PKGTYPE:"
  11999.   return 1
  12000. }
  12001.  
  12002. Has_Selections()
  12003. {
  12004.   Check_File $FILE_PKGS_SEL && return 0
  12005.   Msg ":ERR_MISSING_SELECTIONS:"
  12006.   return 1        
  12007. }
  12008.  
  12009. Has_Source()
  12010. {
  12011.   if [ -z "$DIR_SOURCE" ]; then
  12012.     Error ":ERR_MISSING_SOURCE:"
  12013.     return 1        
  12014.   fi
  12015.   return 0
  12016. }
  12017.  
  12018. Has_Pkgs()
  12019. {
  12020.   if [ -z "$DIR_PKGS" ]; then
  12021.     Error ":ERR_MISSING_SOURCE:"
  12022.     return 1        
  12023.   fi
  12024.   if [ ! -d "$DIR_PKGS/RPMS" ]; then
  12025.     return 1
  12026.   fi
  12027.   return 0
  12028. }
  12029.  
  12030. # checks if target path is valid
  12031. #
  12032. Has_Target_Path()
  12033. {
  12034.   local f_name=Has_Target_Path
  12035.   local f_args=0 # DIR_TARGET ->
  12036.  
  12037.   Check_Args $f_name $f_args $# "$@" || return 255
  12038.   if [ -z "$DIR_TARGET" ]; then
  12039.     Error ":ERR_MISSING_TARGET_PATH:"
  12040.     return 1
  12041.   fi
  12042.   if [ ! -d "$DIR_TARGET" ]; then
  12043.     Error "$DIR_TARGET ; :ERR_INVALID_TARGET_PATH:"
  12044.     return 1
  12045.   fi
  12046.   return 0
  12047. }    
  12048.  
  12049. Menu_Pkg()
  12050. {
  12051.   local cmd=
  12052.  
  12053.   # "Menu_Pkg_Select" ":MENU_PKG_SELECT:"
  12054.   while [ 1 ]; do
  12055.     $CMD_BOX --help ":MENU_PKG_HELP:" \
  12056. --title ":MENU_PKG_TITLE:" \
  12057. --menu ":MENU_PKG_TEXT:" \
  12058. "Choose_Install_Source" ":CHOOSE_INSTALL_SOURCE:" \
  12059. "Menu_Pkg_Info" ":MENU_PKG_INFO:" \
  12060. "Menu_Pkg_Add" ":MENU_PKG_ADD:" \
  12061. "Menu_Pkg_Remove" ":MENU_PKG_REMOVE:" 2> $FILE_TMP_ANSWER
  12062.     if [ $? -ne 0 ]; then
  12063.       Debug "Menu_Pkg submenu retval -ne 0 !" 
  12064.       return 1
  12065.     fi
  12066.     if [ -s $FILE_TMP_ANSWER ]; then
  12067.       cmd="`cat $FILE_TMP_ANSWER`"
  12068.       if [ -n "$cmd" ]; then
  12069.     $cmd
  12070.       else
  12071.     Debug "Menu_Pkg leaves empty command !" 
  12072.       fi
  12073.     else
  12074.       Debug "Menu_Pkg leaves empty $FILE_TMP_ANSWER !" 
  12075.     fi
  12076.   done
  12077. }
  12078.  
  12079. Menu_Pkg_Info()
  12080. {
  12081.   Info_lite ":INFO_BUILDING_PKGLIST: :INFO_WAIT:"
  12082.   Choose --menutitle ":MENU_SHOW_PKGS_MENUTITLE:" --build "Build_RPM_Infos" PKG_INFO || return 1
  12083.   rpm -qi "$ANSWER" > /tmp/LST/val 2> /dev/null
  12084.   if [ $? -eq 0 ]; then
  12085.     $CMD_BOX --browse /tmp/LST/val
  12086.   fi
  12087.   return 0
  12088. }
  12089.  
  12090. List_RPM_Installed()
  12091. {
  12092.   rpm -qa | sed 's/^\(.*\)-[^-]*-[^-]*$/\1/' | sort | uniq
  12093. }
  12094.  
  12095. List_Pkgs_Known()
  12096. {
  12097.   build_menu -d $FILE_PKGS_DATA -n -p ":1:" | sort | uniq
  12098. }
  12099.  
  12100. List_Pkgs_Not_Installed()
  12101. {
  12102.   local p
  12103.   local known=/tmp/LST/pkgs.known
  12104.   local inst=/tmp/LST/pkgs.inst
  12105.  
  12106.   List_Pkgs_Known > $known
  12107.   List_RPM_Installed > $inst
  12108.  
  12109.   # fgrep -v -f $inst $known
  12110.   for p in `cat $known` ; do
  12111.     if [ -z "`fgrep -x $p $inst`" ]; then
  12112.       echo "$p"
  12113.     fi
  12114.   done
  12115. }
  12116.  
  12117. Build_RPM_Installed()
  12118. {
  12119.   touch $FILE_PKGS_SEL
  12120.   build_menu -R -t $FILE_PKGS_SEL -d $FILE_PKGS_DATA -f
  12121. }
  12122.  
  12123. Build_RPM_Infos()
  12124. {
  12125.   List_RPM_Installed | do_quote
  12126. }
  12127.  
  12128. Build_Pkgs_Not_Installed()
  12129. {
  12130.   touch $FILE_PKGS_SEL
  12131.   build_menu -R -t $FILE_PKGS_SEL -d $FILE_PKGS_DATA -f
  12132. }
  12133.  
  12134. Do_Pkg_Add()
  12135. {
  12136.   local p=$1
  12137.   local pfile
  12138.  
  12139.   Do_Find_File_To_Pkg $p
  12140.   pfile="$PKG_FILE"
  12141.   Debug "Install $p ($pfile)" 
  12142.   Do_Raw_rpm_Install $pfile $p
  12143.   return 0
  12144. }
  12145.  
  12146. Menu_Pkg_Add()
  12147. {
  12148.   local p
  12149.  
  12150.   Has_Pkgs || return 1
  12151.   Info_lite ":INFO_BUILDING_PKGLIST: :INFO_WAIT:"
  12152.   List_Pkgs_Not_Installed > $FILE_PKGS_SEL
  12153.   Choose --menutitle ":MENU_SHOW_PKGS_MENUTITLE:" --sumlist --build "Build_Pkgs_Not_Installed" PKG_SELECT_PKGS || return 1
  12154.   mv $FILE_TMP_ANSWER $FILE_PKGS_SEL
  12155.   if [ ! -s $FILE_PKGS_SEL ]; then
  12156.     return 1
  12157.   fi
  12158.   Msg2 PKG_INSTALL || continue
  12159.   Info ":INFO_INSTALLING_PKG: :INFO_WAIT:"
  12160.   Do_Sort_Pkgs
  12161.   Do_Sort_Series
  12162.   Get_Install_Stat
  12163.   for p in `cat $FILE_PKGS_SEL` ; do
  12164.     Do_Pkg_Add $p
  12165.   done
  12166.   rm -f $FILE_PKGS_SEL
  12167.   return 0
  12168. }
  12169.  
  12170. Menu_Pkg_Remove()
  12171. {
  12172.   local p
  12173.   
  12174.   Info_lite ":INFO_BUILDING_PKGLIST: :INFO_WAIT:"
  12175.   List_RPM_Installed > $FILE_PKGS_SEL
  12176.   Choose --menutitle ":MENU_SHOW_PKGS_MENUTITLE:" --sumlist --build "Build_RPM_Installed" PKG_REMOVE || return 1
  12177.   mv $FILE_TMP_ANSWER $FILE_PKGS_SEL
  12178.   if [ -s $FILE_PKGS_SEL ]; then
  12179.     Info ":INFO_REMOVING_PKGS: :INFO_WAIT:"
  12180.     for p in `cat $FILE_PKGS_SEL` ; do
  12181.       Do_Pkg_Remove $p
  12182.     done
  12183.   fi
  12184.   rm -f $FILE_PKGS_SEL
  12185.   return 0
  12186. }
  12187.  
  12188. Do_Check_Freespace()
  12189. {
  12190.   local TOTALSPACE=
  12191.   local need_MB=
  12192.   local free_MB=
  12193.  
  12194.   # calculate the needed space
  12195.   Do_Calc_Needspace $FILE_PKGS_SEL
  12196.   Debug "NEEDSPACE='$NEEDSPACE'"
  12197.  
  12198.   # calculate the free space
  12199.   Do_Calc_Freespace $DIR_TARGET
  12200.  
  12201.   # to get on the save side, we require an additional SPARESPACE
  12202.   TOTALSPACE=`do_calc $NEEDSPACE + $SPARESPACE`
  12203.   Debug "TOTALSPACE='$TOTALSPACE', FREESPACE='$FREESPACE'"
  12204.   free_MB="`do_calc $FREESPACE / 1048576`"
  12205.   need_MB="`do_calc $TOTALSPACE / 1048576`"
  12206.   if [ "$free_MB" = "$need_MB" ]; then
  12207.     need_MB="`do_calc $need_MB + 1`"
  12208.   fi
  12209.   if [ $need_MB -gt $free_MB ]; then
  12210.     if [ $free_MB -gt 0 ]; then
  12211.       Warn "($need_MB MB > $free_MB MB) ; :ERR_USR_TOO_SMALL:" || return 1
  12212.     else
  12213.       Debug "Warning free_MB is negative ($free_MB) Integer overflow?"
  12214.     fi
  12215.   fi
  12216.   return 0
  12217. }
  12218.  
  12219. Menu_Pkg_Select()
  12220. {
  12221.   prep_use INSTALL || return 1
  12222.   prep_use RPM_INSTALL || return 1
  12223.   Has_Source || return 1
  12224.   Has_Target_Path || return 1
  12225.   Check_Pkg_Database || return 1
  12226.   Check_Pkg_Index || return 1
  12227.  
  12228.   Info ":INFO_WAIT:"
  12229.  
  12230.   while [ 1 ]; do
  12231.     if [ "`get_val -f /etc/lst.cnf CONF_COL_EDITION`" = "SBA" ]; then
  12232.       build_menu -n -p ":1:" -d $FILE_PKGS_DATA > /usr/lib/LST/pkgs.sel
  12233.       ANSWER="Menu_Pkg_Select_Preset sel"
  12234.     else
  12235.       if [ -f /usr/lib/LST/pkgs.sel ]; then
  12236.         Choose --prefix "MENU" --default "Menu_Pkg_Select_Preset sel" --build "Build_PKG_SELECT" PKG_SELECT || return 1
  12237.       else
  12238.         Choose --prefix "MENU" --default "Menu_Pkg_Select_Preset rec" --build "Build_PKG_SELECT" PKG_SELECT || return 1
  12239.       fi
  12240.     fi
  12241.     COMMAND="$ANSWER"
  12242.     $COMMAND || continue
  12243.  
  12244.     Do_Check_Freespace || continue
  12245.  
  12246.     break
  12247.   done 
  12248.   # save final package selection
  12249.   if [ -f $FILE_PKGS_SEL ]; then
  12250.       cp -a $FILE_PKGS_SEL /usr/lib/LST/pkgs.sel
  12251.   fi
  12252.   return 0
  12253. }
  12254.  
  12255. Menu_Pkg_Select_Pkgs()
  12256. {
  12257.   rm -f $FILE_SERIES_SEL
  12258.   rm -f $FILE_PKGS_SEL
  12259.   Info_lite ":INFO_BUILDING_PKGLIST: :INFO_WAIT:"
  12260.   touch $FILE_PKGS_SEL
  12261.  
  12262.   # generate pkglist from pkgs.db
  12263.   build_menu -s basis -c 2 -f -d $FILE_PKGS_DATA > /tmp/LST/HOPE
  12264.   Choose --menutitle ":MENU_SHOW_PKGS_MENUTITLE:" --sumlist --build "Build_PKG" PKG_SELECT_PKGS || return 1
  12265.   mv $FILE_TMP_ANSWER $FILE_PKGS_SEL
  12266.  
  12267.   # generate serieslist from pkglist
  12268.   Info_lite ":INFO_UPDATING_SELECTIONS:"
  12269.   build_menu -U 0 -t $FILE_PKGS_SEL -d $FILE_PKGS_DATA | db_printf -p ":-2:-3:" | fgrep -v ':0' | db_printf -p ":1:" > $FILE_SERIES_SEL
  12270.  
  12271.   return 0
  12272. }
  12273.  
  12274. Menu_Pkg_Select_Preset()
  12275. {
  12276.   local preset=$1
  12277.  
  12278.   # initially NEEDSPACE is in MB
  12279.   export NEEDSPACE=0
  12280.  
  12281.   # generate selection list depending on the preset type
  12282.   Get_Preset_Pkgs $preset > $FILE_PKGS_SEL
  12283.  
  12284.   # generate serieslist from pkglist
  12285.   Info_lite ":INFO_UPDATING_SELECTIONS:"
  12286.   build_menu -U 0 -t $FILE_PKGS_SEL -d $FILE_PKGS_DATA | db_printf -p ":-2:-3:" | fgrep -v ':0' | db_printf -p ":1:" > $FILE_SERIES_SEL
  12287.  
  12288.   # ask for X Server if recommended pkgs
  12289.   if [ "$preset" = "minx" -o "$preset" = "small" -o "$preset" = "rec" ]; then
  12290.     while [ 1 ]; do
  12291.       Choose --sumlist --build "build_menu -f -u XSERV -d $FILE_PKGS_DATA" PKG_SELECT_SERVICES_XSERVER || return 1
  12292.       if [ ! -s $FILE_TMP_ANSWER ]; then
  12293.     Error ":ERR_NEED_AT_LEAST_ONE_XSERVER:"
  12294.     continue
  12295.       fi
  12296.       cat $FILE_TMP_ANSWER >> $FILE_PKGS_SEL
  12297.       break
  12298.     done
  12299.   fi
  12300.  
  12301.   return 0
  12302. }
  12303.  
  12304. Menu_Pkg_Select_Series()
  12305. {
  12306.   local series=
  12307.   local choice=
  12308.   local retval=
  12309.  
  12310.   # reset all selections
  12311.   Info_lite ":INFO_BUILDING_SERIESLIST:"
  12312.   rm -f $FILE_PKGS_SEL
  12313.   rm -f $FILE_SERIES_SEL
  12314.   for i in $LST_SERIES ; do
  12315.     rm -f $DIR_LST_TMP/$i.sel
  12316.   done
  12317.  
  12318.   # loop for all series
  12319.   while [ 1 ]; do
  12320.     Choose --menutitle ":MENU_SHOW_SERIES_MENUTITLE:" --menu --build Build_SERIES PKG_SELECT_SERIES
  12321.     retval=$?
  12322.     if [ $retval -eq 255 ]; then
  12323.       return 255
  12324.     fi
  12325.     if [ $retval -ne 0 ]; then
  12326.       # workaround for unclear continue/abort
  12327.       if [ -f $FILE_PKGS_SEL ]; then
  12328.         ANSWER=ENDE
  12329.       else
  12330.         return 1
  12331.       fi
  12332.     fi
  12333.     SERIES="$ANSWER"
  12334.     if [ "$ANSWER" = "USAGE" ]; then
  12335.       Show_Filesystem_Usage $DIR_TARGET
  12336.       continue
  12337.     fi
  12338.     if [ "$ANSWER" = "ENDE" ]; then
  12339.       if [ "$DIR_TARGET" = "/" ]; then
  12340.     return 0
  12341.       fi
  12342.       if [ -s $FILE_SERIES_SEL ]; then
  12343.     fgrep -x "basis" $FILE_SERIES_SEL >/dev/null
  12344.     if [ $? -eq 0 ]; then
  12345.       return 0
  12346.     fi
  12347.       fi
  12348.       Msg ":ERR_NO_BASIS_SELECTED:"
  12349.       continue
  12350.     fi
  12351.     Choose --build "Build_SELECT_PRIO $SERIES" SELECT_PRIO || continue
  12352.     CHOICE="$ANSWER"
  12353.     if [ "$CHOICE" = "0" ]; then
  12354.       if [ -s $DIR_LST_TMP/$SERIES.sel -a -s $FILE_PKGS_SEL ]; then
  12355.     fgrep -vxf $DIR_LST_TMP/$SERIES.sel $FILE_PKGS_SEL > $FILE_PKGS_SEL.tmp
  12356.     mv $FILE_PKGS_SEL.tmp $FILE_PKGS_SEL
  12357.       fi    
  12358.       rm -f $DIR_LST_TMP/$SERIES.sel
  12359.       if [ -s $FILE_SERIES_SEL -a -n "$SERIES" ]; then
  12360.     fgrep -vx "$SERIES" $FILE_SERIES_SEL > $FILE_SERIES_SEL.tmp
  12361.     mv $FILE_SERIES_SEL.tmp $FILE_SERIES_SEL
  12362.       fi
  12363.       continue
  12364.     fi
  12365.  
  12366.     Info_lite ":INFO_BUILDING_PKGLIST: :INFO_WAIT:"
  12367.     touch $FILE_PKGS_SEL
  12368.     if [ "$CHOICE" = "4" ]; then
  12369.       build_menu -T $FILE_PKGS_SEL -d $FILE_PKGS_DATA | build_menu -N -s $SERIES -T $DIR_LST_TMP/$SERIES.sel -f > /tmp/LST/HOPE
  12370.     else
  12371.       build_menu -T $FILE_PKGS_SEL -d $FILE_PKGS_DATA | build_menu -N -s $SERIES -c $CHOICE -f > /tmp/LST/HOPE
  12372.     fi
  12373.     Choose --menutitle ":MENU_SHOW_PKGS_MENUTITLE:" --sumlist --build "Build_PKG" PKG_SELECT_PKGS || continue 
  12374.  
  12375.     Info_lite ":INFO_UPDATING_SELECTIONS:"
  12376.     # update selectlist
  12377.     mv $FILE_TMP_ANSWER $DIR_LST_TMP/$SERIES.sel
  12378.     rm -f $FILE_PKGS_SEL
  12379.     for i in $LST_SERIES ; do
  12380.       if [ -s $DIR_LST_TMP/$i.sel ]; then
  12381.     cat $DIR_LST_TMP/$i.sel >> $FILE_PKGS_SEL
  12382.       else
  12383.     rm -f $DIR_LST_TMP/$i.sel
  12384.       fi
  12385.     done
  12386.     # update serieslist
  12387.     touch $FILE_SERIES_SEL
  12388.     if [ -z "`fgrep -x $SERIES $FILE_SERIES_SEL`" ]; then
  12389.       if [ "$SERIES" = "basis" ]; then
  12390.     echo "$SERIES" > $FILE_SERIES_SEL.tmp
  12391.     cat $FILE_SERIES_SEL >> $FILE_SERIES_SEL.tmp
  12392.     mv $FILE_SERIES_SEL.tmp $FILE_SERIES_SEL
  12393.       else
  12394.     echo "$SERIES" >> $FILE_SERIES_SEL
  12395.       fi
  12396.     fi
  12397.   done
  12398.  
  12399.   return 0
  12400. }
  12401.  
  12402.  
  12403. Menu_Pkg_Select_Services()
  12404. {
  12405.   local i=
  12406.   local servok=0
  12407.  
  12408.   local shadsel=0
  12409.   local xsel=0
  12410.   local docsel=0
  12411.   local textsel=0
  12412.   local gamessel=0
  12413.   local develsel=0
  12414.   local netsel=0
  12415.   local servsel=0
  12416.   local develdocsel=0
  12417.   local netshadsel=0
  12418.   local netdocsel=0
  12419.   local netservsel=0
  12420.   local xshadsel=0
  12421.   local xtextsel=0
  12422.   local xgamessel=0
  12423.   local xnetsel=0
  12424.   local xdevelsel=0
  12425.   local xdeveldocsel=0
  12426.  
  12427.   while [ 1 ]; do
  12428.     # reset all selections
  12429.     rm -f $FILE_PKGS_SEL
  12430.     i=
  12431.     shadsel=0
  12432.     xsel=0
  12433.     docsel=0
  12434.     textsel=0
  12435.     gamessel=0
  12436.     develsel=0
  12437.     netsel=0
  12438.     servsel=0
  12439.     develdocsel=0
  12440.     netshadsel=0
  12441.     netdocsel=0
  12442.     netservsel=0
  12443.     xshadsel=0
  12444.     xtextsel=0
  12445.     xgamessel=0
  12446.     xnetsel=0
  12447.     xdevelsel=0
  12448.     xdeveldocsel=0
  12449.  
  12450.     # offer all MAIN choices
  12451.     echo "MAIN" > $FILE_META_SEL
  12452.  
  12453.     # for now we need SHADOW by default
  12454.     echo "SHAD" >> $FILE_META_SEL
  12455.     shadsel=1
  12456.  
  12457.     # ask for additional services (meta level)
  12458.     $CMD_BOX --multi ":CHOOSE_SERVICES:" \
  12459. --help ":CHOOSE_SERVICES_HELP:" \
  12460. "X" ":TYPE_SERVICE_X:" S \
  12461. "DOC" ":TYPE_SERVICE_DOC:" S \
  12462. "TEXT" ":TYPE_SERVICE_TEXT:" S \
  12463. "GAMES" ":TYPE_SERVICE_GAMES:" U \
  12464. "DEVEL" ":TYPE_SERVICE_DEVEL:" U \
  12465. "NET" ":TYPE_SERVICE_NET:" U \
  12466. "SERV" ":TYPE_SERVICE_SERV:" U 2>> $FILE_META_SEL || return 1
  12467.  
  12468.     servok=
  12469.     # reset all selections
  12470.     rm -f $FILE_PKGS_SEL
  12471.  
  12472.     fgrep -x X $FILE_META_SEL > /dev/null
  12473.     if [ $? -eq 0 ]; then
  12474.       while [ 1 ]; do
  12475.     # ask for X Server
  12476.     Choose --sumlist --build "build_menu -f -u XSERV -d $FILE_PKGS_DATA" PKG_SELECT_SERVICES_XSERVER || return 1
  12477.     if [ ! -s $FILE_TMP_ANSWER ]; then
  12478.       Error ":ERR_NEED_AT_LEAST_ONE_XSERVER:"
  12479.       continue
  12480.     fi
  12481.     cat $FILE_TMP_ANSWER >> $FILE_PKGS_SEL
  12482.     servok=1
  12483.     break
  12484.       done
  12485.     else
  12486.       servok=1
  12487.     fi
  12488.  
  12489.     Info_lite ":INFO_BUILDING_SERVICELIST:"
  12490.  
  12491.     # analyse selections
  12492.     fgrep -x X $FILE_META_SEL > /dev/null && xsel=1
  12493.     fgrep -x DOC $FILE_META_SEL > /dev/null && docsel=1
  12494.     fgrep -x TEXT $FILE_META_SEL > /dev/null && textsel=1
  12495.     fgrep -x GAMES $FILE_META_SEL > /dev/null && gamessel=1
  12496.     fgrep -x DEVEL $FILE_META_SEL > /dev/null && develsel=1
  12497.     fgrep -x NET $FILE_META_SEL > /dev/null && netsel=1
  12498.     fgrep -x SERV $FILE_META_SEL > /dev/null && servsel=1
  12499.     
  12500.     # hardcoded rules ;-)
  12501.  
  12502.     # devel rules
  12503.     if [ $develsel -eq 1 -a $docsel -eq 1 ]; then
  12504.       develdocsel=1
  12505.       echo "DEVELDOC" >> $FILE_META_SEL
  12506.     fi
  12507.  
  12508.     #
  12509.     # net rules
  12510.     #
  12511.     if [ $netsel -eq 1 -a $shadsel -eq 1 ]; then
  12512.       netshadsel=1
  12513.       echo "NETSHAD" >> $FILE_META_SEL
  12514.     fi
  12515.     if [ $netsel -eq 1 -a $docsel -eq 1 ]; then
  12516.       netdocsel=1
  12517.       echo "NETDOC" >> $FILE_META_SEL
  12518.     fi
  12519.     if [ $netsel -eq 1 -a $servsel -eq 1 ]; then
  12520.       netservsel=1
  12521.       echo "NETSERV" >> $FILE_META_SEL
  12522.     fi
  12523.  
  12524.     #
  12525.     # X rules
  12526.     #
  12527.     if [ $xsel -eq 1 -a $shadsel -eq 1 ]; then
  12528.       xshadsel=1
  12529.       echo "XSHAD" >> $FILE_META_SEL
  12530.     fi
  12531.     if [ $xsel -eq 1 -a $textsel -eq 1 ]; then
  12532.       xtextsel=1
  12533.       echo "XTEXT" >> $FILE_META_SEL
  12534.     fi
  12535.     if [ $xsel -eq 1 -a $gamessel -eq 1 ]; then
  12536.       xgamessel=1
  12537.       echo "XGAMES" >> $FILE_META_SEL
  12538.     fi
  12539.     if [ $xsel -eq 1 -a $netsel -eq 1 ]; then
  12540.       xnetsel=1
  12541.       echo "XNET" >> $FILE_META_SEL
  12542.     fi
  12543.     if [ $xsel -eq 1 -a $develsel -eq 1 ]; then
  12544.       xdevelsel=1
  12545.       echo "XDEVEL" >> $FILE_META_SEL
  12546.     fi
  12547.     if [ $xsel -eq 1 -a $develdocsel -eq 1 ]; then
  12548.       xdeveldocsel=1
  12549.       echo "XDEVELDOC" >> $FILE_META_SEL
  12550.     fi
  12551.  
  12552.     # generate servicelist
  12553.     rm -f $FILE_SERVICES_SEL
  12554.     for i in `cat $FILE_META_SEL` ; do
  12555.       fgrep ":$i:" $FILE_META_DATA | cut -d':' -f 3 >> $FILE_SERVICES_SEL 
  12556.     done
  12557.  
  12558.     echo "$CMD_BOX -a --help \":MENU_PKG_SELECT_SERVICES_HELP:\" \\" > $FILE_TMP_COMMAND
  12559.     echo "--sumlist \":MENU_PKG_SELECT_SERVICES_TEXT:\" \\" >> $FILE_TMP_COMMAND
  12560.     for i in `cat $FILE_SERVICES_SEL` ; do
  12561.       Debug "# build_menu -S -f -u $i -d $FILE_PKGS_DATA"
  12562.       build_menu -S -f -u $i -d $FILE_PKGS_DATA >> $FILE_TMP_COMMAND
  12563.     done
  12564.     rm -f $FILE_SERVICES_SEL
  12565.     echo "2> $FILE_TMP_MSG" >> $FILE_TMP_COMMAND
  12566.     chmod 755 $FILE_TMP_COMMAND
  12567.  
  12568.     # choose services
  12569.     sh $FILE_TMP_COMMAND && break
  12570.   done
  12571.     
  12572.   Info_lite ":INFO_BUILDING_SERVICELIST:"
  12573.  
  12574.   # generate pkglist
  12575.   mv $FILE_TMP_MSG $FILE_SERVICES_SEL
  12576.   for i in `cat $FILE_SERVICES_SEL` ; do
  12577.     build_menu -u $i -n -p ":1:" -d $FILE_PKGS_DATA >> $FILE_PKGS_SEL
  12578.   done
  12579.  
  12580.   # generate serieslist from pkglist
  12581.   Info_lite ":INFO_UPDATING_SELECTIONS:"
  12582.   build_menu -U 0 -t $FILE_PKGS_SEL -d $FILE_PKGS_DATA | db_printf -p ":-2:-3:" | fgrep -v ':0' | db_printf -p ":1:" > $FILE_SERIES_SEL
  12583.  
  12584.   return 0
  12585. }
  12586.  
  12587.  
  12588. # libLSTuser - user administration library shared between several scripts
  12589. #
  12590. # Copyright (C) 1993-1997 Ralf Flaxa, LST Software GmbH, Erlangen, Germany
  12591. #
  12592.  
  12593. List_USER()
  12594. {
  12595.     db_printf -n -p ":-1:3:4:-5:" -f $FILE_ETC_PASSWD
  12596. }
  12597.  
  12598. Build_USER()
  12599. {
  12600.     List_USER | do_quote
  12601. }
  12602.  
  12603. Build_USER_DEL()
  12604. {
  12605.     # filter out system and NIS users. should not be deleted.
  12606.     List_USER | sed '{
  12607.         /^root /d
  12608.         /^bin /d
  12609.         /^daemon /d
  12610.         /^adm /d
  12611.         /^lp /d
  12612.         /^sync /d
  12613.         /^shutdown /d
  12614.         /^halt /d
  12615.         /^mail /d
  12616.         /^news /d
  12617.         /^uucp /d
  12618.         /^operator /d
  12619.         /^games /d
  12620.         /^gopher /d
  12621.         /^ftp /d
  12622.         /^man /d
  12623.         /^nobody /d
  12624.         /^+/d
  12625.         }' | do_quote
  12626. }
  12627.  
  12628. List_GROUP()
  12629. {
  12630.     db_printf -n -p ":-1:3:4:" -f $FILE_ETC_GROUP
  12631. }
  12632.  
  12633. Build_GROUP()
  12634. {
  12635.     List_GROUP | do_quote
  12636. }
  12637.  
  12638. Check_GID_Known()
  12639. {
  12640.     local f_name=Check_GID_Known
  12641.     local f_args=1 # (gid) ->
  12642.  
  12643.     Check_Args $f_name $f_args $# "$@" || return 255
  12644.     if [ -n "`cut -d':' -f 3 $FILE_ETC_GROUP | sed -n "/^$1$/p"`" ]
  12645.     then return 0
  12646.     else return 1
  12647.     fi
  12648. }
  12649.  
  12650. Check_Group_Known()
  12651. {
  12652.     local f_name=Check_Group_Known
  12653.     local f_args=1 # (groupname) ->
  12654.  
  12655.     Check_Args $f_name $f_args $# "$@" || return 255
  12656.     if [ -n "`sed -n "/^$1:/p" $FILE_ETC_GROUP`" ]
  12657.     then return 0
  12658.     else return 1
  12659.     fi
  12660. }
  12661.  
  12662. Check_UID_Known()
  12663. {
  12664.     local f_name=Check_UID_Known
  12665.     local f_args=1 # (uid) ->
  12666.  
  12667.     Check_Args $f_name $f_args $# "$@" || return 255
  12668.     if [ -n "`cut -d':' -f 3 $FILE_ETC_PASSWD | sed -n "/^$1$/p"`" ]; then
  12669.          return 0
  12670.     else
  12671.         return 1
  12672.     fi
  12673. }
  12674.  
  12675. Check_User_Known()
  12676. {
  12677.     local f_name=Check_User_Known
  12678.     local f_args=1 # (username) ->
  12679.  
  12680.     Check_Args $f_name $f_args $# "$@" || return 255
  12681.     if [ -n "`sed -n "/^$1:/p" $FILE_ETC_PASSWD`" ]; then
  12682.         return 0
  12683.     else
  12684.         return 1
  12685.     fi
  12686. }
  12687.  
  12688. Get_Next_UID()
  12689. {
  12690.     local start_uid=500
  12691.     local stop_uid=65534
  12692.     local curr_uid=$start_uid
  12693.  
  12694.     while [ 1 ]; do
  12695.         if Check_UID_Known $curr_uid ; then
  12696.             curr_uid="`do_calc $curr_uid + 1`"
  12697.         else
  12698.             break
  12699.         fi
  12700.         # stop searching at user nobody
  12701.         if [ $curr_uid -eq $stop_uid ]; then
  12702.             echo ""
  12703.             return 1
  12704.         fi
  12705.     done
  12706.     echo "$curr_uid"
  12707.     return 0
  12708. }
  12709.  
  12710. Menu_User_Add()
  12711. {
  12712.     local newusername=
  12713.     local newuseruid=
  12714.     local newusergroup=
  12715.     local newusergid=
  12716.     local newuserhome=
  12717.     local newusershell=
  12718.     local newusergecos=
  12719.     local homeprefix=
  12720.     local skipall=
  12721.   
  12722.     if [ $# -gt 0 -a "X$1" = 'X--first' ]; then
  12723.         newusername=col
  12724.         newuseruid=500
  12725.         newusergroup=users
  12726.         newusergid=100
  12727.         newuserhome=/home/col
  12728.         newusershell=/bin/bash
  12729.         newusergecos="Caldera OpenLinux User"
  12730.         homeprefix=/home
  12731.         #skipall=true
  12732.     fi
  12733.  
  12734.     # ask logname
  12735.     while [ 1 ]; do
  12736.         if [ "$skipall" = "true" ]; then
  12737.             break
  12738.         fi
  12739.         while [ 1 ]; do
  12740.             while [ 1 ]; do
  12741.                 Ask_String LOGNAME_USER $newusername || return 1
  12742.                 newusername="$ANSWER"
  12743.                 if [ "$newusername" != "`echo $newusername | sed 's/ //'`" ]; then
  12744.                     Error "<$newusername> ; a username may not contain any spaces."
  12745.                     continue
  12746.                 fi
  12747.                 if [ -n "$newusername" ]; then
  12748.                     break
  12749.                 fi
  12750.             done
  12751.             if Check_User_Known $newusername ; then
  12752.                 Error "$newusername ; :ERR_LOGNAME_EXISTS:"
  12753.                 continue
  12754.             else
  12755.                 break
  12756.             fi
  12757.         done
  12758.  
  12759.         # ask UID     
  12760.         while [ 1 ]; do
  12761.             if [ -z "$newuseruid" ]; then
  12762.                 newuseruid="`Get_Next_UID`"
  12763.             fi
  12764.             Ask_String UID_USER $newuseruid || return 1
  12765.             newuseruid="$ANSWER"
  12766.             if [ -z "$newuseruid" ]; then
  12767.                 continue
  12768.             fi
  12769.             if Check_UID_Known $newuseruid ; then
  12770.                 Error "$newuserid ; :ERR_UID_EXISTS:"
  12771.                 continue
  12772.             else
  12773.                 break
  12774.             fi
  12775.         done
  12776.  
  12777.         # ask group
  12778.         newusergroup="`Get_Val CONF_GROUP_DEFAULT`"
  12779.         Choose --build Build_GROUP GROUP_USER $newusergroup || return 1
  12780.         newusergroup="$ANSWER"
  12781.         newusergid="`sed -n "/^$newusergroup:/p" $FILE_ETC_GROUP | cut -d':' -f 3`"
  12782.  
  12783.         # ask home
  12784.         newuserhome="`Get_Val CONF_HOME_DEFAULT`"
  12785.         if [ -z "$newuserhome" ]; then
  12786.             newuserhome=/home
  12787.         fi
  12788.         newuserhome="$newuserhome/$newusername"
  12789.         Ask_String HOME_USER $newuserhome || return 1
  12790.         newuserhome="$ANSWER"
  12791.         homeprefix="`echo $newuserhome | sed 's,^\(.*\)/[^/]*,\1,'`"
  12792.  
  12793.         # ask shell
  12794.         newusershell="`Get_Val CONF_SHELL_DEFAULT`"
  12795.         Choose --build "List box SHELL" SHELL_USER $newusershell || return 1
  12796.         newusershell="$ANSWER"
  12797.  
  12798.         # ask comment field
  12799.         Ask_String COMMENT_USER "$newusergecos" || return 1
  12800.         newusergecos="$ANSWER"
  12801.         if [ -n "$newusergecos" ]; then
  12802.             gecos="-c \"$newusergecos\""
  12803.         fi
  12804.         break
  12805.     done
  12806.  
  12807.     # Note: expire date is still set statically to 31th Dec 1999 (-e 10956)
  12808.     # Ask_String EXPIRE_DATE $CONF_ACCOUNT_EXPIRE_DATE
  12809.     # expire_date="$ANSWER"
  12810.     expire_date="10956"
  12811.  
  12812.     # FIXME: useradd now comes from the live filesystem
  12813.     # prep_use /usr/sbin/useradd
  12814.     mkdir -p $homeprefix
  12815.  
  12816.     if [ -n "$newusergecos" ]; then
  12817.         useradd -g "$newusergid" -u "$newuseruid" -c "$newusergecos" -d "$newuserhome" -s "$newusershell" -m "$newusername" || continue
  12818.     else
  12819.         useradd -g "$newusergid" -u "$newuseruid" -d "$newuserhome" -s "$newusershell" -m "$newusername" || continue
  12820.     fi
  12821.  
  12822.     chmod 644 $DIR_TARGET/etc/passwd
  12823.  
  12824.     mkdir -p $DIR_TARGET/$newuserhome
  12825.     if [ -d $DIR_TARGET/etc/skel ]; then
  12826.         cp -a $DIR_TARGET/etc/skel/. $DIR_TARGET/$newuserhome
  12827.     fi
  12828.     chown -R $newuseruid.$newusergid $DIR_TARGET/$newuserhome
  12829.  
  12830.     LAST_USER="$newusername"
  12831.  
  12832.     Do_Set_Password $newusername
  12833.     return 0
  12834. }
  12835.  
  12836. Menu_User_Del()
  12837. {
  12838.     local deluser=
  12839.  
  12840.     Choose --build Build_USER_DEL USER_DEL || return 1
  12841.     deluser="$ANSWER"
  12842.  
  12843.     $CMD_BOX --help ":ASK_USER_DEL_ACK_HELP:" \
  12844. --title ":ASK_USER_DEL_ACK_TITLE:" \
  12845. --bool "$deluser ; :ASK_USER_DEL_ACK_TEXT:" 2> $FILE_TMP_ANSWER || return 1
  12846.     touch $FILE_TMP_ANSWER
  12847.     ANSWER="`cat $FILE_TMP_ANSWER`"
  12848.     rm -f $FILE_TMP_ANSWER
  12849.     if [ "$ANSWER" = "0" ]; then
  12850.         $DO_SIMULATE userdel -r $deluser
  12851.     fi
  12852. }
  12853.  
  12854. Menu_User_Show()
  12855. {
  12856.     List_USER > $FILE_TMP_MSG
  12857.     $CMD_BOX --help ":MENU_SHOW_USER_HELP:" \
  12858. --title ":MENU_SHOW_USER_TITLE:" \
  12859. --menutitle ":MENU_SHOW_USER_MENUTITLE:" \
  12860. --text ":MENU_SHOW_USER_TEXT:" \
  12861. --browse $FILE_TMP_MSG 2> /dev/null
  12862. }
  12863.  
  12864. Menu_Group_Add()
  12865. {
  12866.     local newgrp=
  12867.     local newgid=
  12868.  
  12869.     Ask_String GROUP_ADD || return 1
  12870.     newgrp="$ANSWER"
  12871.  
  12872.     Ask_String GROUP_GID || return 1
  12873.     newgid="$ANSWER"
  12874.  
  12875.     $CMD_BOX --help ":ASK_GROUP_ADD_ACK_HELP:" \
  12876. --title ":ASK_GROUP_ADD_ACK_TITLE:" \
  12877. --bool ":ASK_GROUP_ADD_ACK_TEXT:" 2> $FILE_TMP_ANSWER || return 1
  12878.  
  12879.     touch $FILE_TMP_ANSWER
  12880.     ANSWER="`cat $FILE_TMP_ANSWER`"
  12881.     rm -f $FILE_TMP_ANSWER
  12882.     if [ "$ANSWER" = "0" ]; then
  12883.         $DO_SIMULATE groupadd -g $newgid $newgrp
  12884.     fi
  12885. }
  12886.  
  12887. Menu_Group_Del()
  12888. {
  12889.     local delgroup=
  12890.     Choose --build Build_GROUP GROUP_DEL || return 1
  12891.     delgroup="$ANSWER"
  12892.  
  12893.     $CMD_BOX --help ":ASK_GROUP_DEL_ACK_HELP:" \
  12894. --title ":ASK_GROUP_DEL_ACK_TITLE:" \
  12895. --bool ":ASK_GROUP_DEL_ACK_TEXT:" 2> $FILE_TMP_ANSWER || return 1
  12896.     touch $FILE_TMP_ANSWER
  12897.     ANSWER="`cat $FILE_TMP_ANSWER`"
  12898.     rm -f $FILE_TMP_ANSWER
  12899.     if [ "$ANSWER" = "0" ]; then
  12900.         $DO_SIMULATE groupdel $delgroup
  12901.     fi
  12902. }
  12903.  
  12904. Menu_Group_Show()
  12905. {
  12906.     List_GROUP > $FILE_TMP_MSG
  12907.     $CMD_BOX --help ":MENU_SHOW_GROUP_HELP:" \
  12908. --title ":MENU_SHOW_GROUP_TITLE:" \
  12909. --menutitle ":MENU_SHOW_GROUP_MENUTITLE:" \
  12910. --text ":MENU_SHOW_GROUP_TEXT:" \
  12911. --browse $FILE_TMP_MSG 2> /dev/null
  12912. }
  12913.  
  12914. Menu_Config_Group_Default()
  12915. {
  12916.     Choose --build Build_GROUP GROUP_DEFAULT || return 1
  12917.     Do_Store CONF_GROUP_DEFAULT "$ANSWER"
  12918. }
  12919.  
  12920. Menu_Config_Home_Default()
  12921. {
  12922.     Ask_String HOME_DEFAULT || return 1
  12923.     Do_Store CONF_HOME_DEFAULT "$ANSWER" || return 1
  12924.     return 0
  12925. }
  12926.  
  12927. Menu_Config_Shell_Default()
  12928. {
  12929.     Choose SHELL SHELL_DEFAULT || return 1
  12930.     Do_Store CONF_SHELL_DEFAULT "$ANSWER" || return 1
  12931.     return 0
  12932. }
  12933.  
  12934. Menu_User_Defaults()
  12935. {
  12936.     local defshell
  12937.     local defhome
  12938.     local defgroup
  12939.  
  12940.     while [ 1 ]; do
  12941.         $CMD_BOX --help ":MENU_USER_DEFAULTS_HELP:" \
  12942. --title ":MENU_USER_DEFAULTS_TITLE:" \
  12943. --menu ":MENU_USER_DEFAULTS_TEXT:" \
  12944. "Menu_Config_Shell_Default" ":CHOOSE_SHELL_DEFAULT: (`Get_Val CONF_SHELL_DEFAULT`)" \
  12945. "Menu_Config_Home_Default" ":ASK_HOME_DEFAULT: (`Get_Val CONF_HOME_DEFAULT`)" \
  12946. "Menu_Config_Group_Default" ":CHOOSE_GROUP_DEFAULT: (`Get_Val CONF_GROUP_DEFAULT`)" 2> $FILE_TMP_ANSWER || break
  12947.         COMMAND="`cat $FILE_TMP_ANSWER`"
  12948.         $COMMAND
  12949.     done
  12950.     return 0
  12951. }
  12952.  
  12953. Menu_Config_User()
  12954. {
  12955.     local item=
  12956.     Check_Chroot ":MENU_CONFIG_USER:" || return 1
  12957.     while [ 1 ]; do
  12958.         if [ -z "$item" ]; then item="Menu_User_Show" ; fi
  12959.         $CMD_BOX --help ":MENU_CONFIG_USER_HELP:" \
  12960. --default "$item" \
  12961. --title ":MENU_CONFIG_USER_TITLE:" \
  12962. --menu ":MENU_CONFIG_USER_TEXT:" \
  12963. "Menu_User_Show" ":MENU_SHOW_USER:" \
  12964. "Menu_User_Add" ":MENU_USER_ADD:" \
  12965. "Menu_User_Del" ":MENU_USER_DEL:" \
  12966. "Menu_Group_Show" ":MENU_SHOW_GROUP:" \
  12967. "Menu_Group_Add" ":MENU_GROUP_ADD:" \
  12968. "Menu_Group_Del" ":MENU_GROUP_DEL:" \
  12969. "Menu_User_Defaults" ":MENU_USER_DEFAULTS:" 2> $FILE_TMP_ANSWER || break
  12970.         COMMAND="`cat $FILE_TMP_ANSWER`"
  12971.         item="$COMMAND"
  12972.         $COMMAND
  12973.     done
  12974.     return 0
  12975. }
  12976.  
  12977.